You are given an array of integers NUM consisting of N elements. This array represents the digits of a number. Your task is to increase the number by 1, or we can say you have to add 1 to this number. The number will be positive, and digits are stored so that the most significant digit is at the starting of the array.
For example:
Let input array is [1,3,2,7] so basically, this array represents the number 1327, the output will be [1,3,2,8].
Note:
The input may have 0 at the starting of the array, e.g., [0,3,5,7] is a valid input, but the output can not have 0 before the most significant digit. So [0,3,5,8] will be a wrong answer, and the correct answer will be [3,5,8].
Input Format:
The first line of input contains a single integer T, representing the number of test cases.
Then the T test cases follow.
The first line of each test case contains a number N denoting the size of the array.
The second line contains N space-separated distinct integers denoting the array elements.
Output format:
For each test case, print the output array elements are separated by space.
The output of every test case will be printed in a separate line.
Note :
You don’t have to print anything. It has already been taken care of. Just implement the given function.
Constraints
1 <= T <=10^2
1 <= N <=10^4
0 <= NUM[i] <= 9
Where 'N' is the number of elements in array 'NUM' and 'NUM[i]' represents the ith digit of number 'NUM'.
Time limit: 1 second
4
4
0 0 9 9
3
1 2 9
7
1 1 1 1 1 1 1
5
9 9 9 9 9
1 0 0
1 3 0
1 1 1 1 1 1 2
1 0 0 0 0 0
4
5
1 1 2 2 1
4
5 6 7 9
7
1 2 3 1 2 3 1
1
9
1 1 2 2 2
5 6 8 0
1 2 3 1 2 3 2
1 0
After the addition of 1, the value of each digit is dependent on the value of the digit just right to it.
We can update values by making a recursive algorithm.
O(N) where N is the length of the array.
As we are making a total of N calls in the recursive function.
O(N) where N is the length of the array.
As we are using recursion stack so our space complexity arises to O(N).