Adding One
Submissions: 5145   Accuracy:

25.73%

  Difficulty: Easy   Marks: 2

Given a non-negative integer represented as an array of digits. Your task is to add 1 to the number ( increment the number by 1). The digits are stored such that the most significant digit is at the starting index of the array.

Example:
If the array has [4, 5, 6], the resultant array should be [4, 5, 7] as 456 + 1 = 457.

Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case contains a single integer N denoting the size of the array. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.

Output:
Print the resultant array.

Constraints:
1 ≤ T ≤ 300
1 ≤ N ≤ 107
0 ≤ A[i] ≤ 9

Example:
Input:
2
4
5 6 7 8
3
9 9 9

Output:
5 6 7 9
1 0 0 0

** For More Input/Output Examples Use 'Expected Output' option **

Author: shef5


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.