An array of decimal digits represents a non-negative integer, most significant digit first, with no leading zeros (except the number 0 itself). Add one to this number and output the resulting digits.
Line 1: an integer n, the number of digits.
Line 2: n space-separated digits (0-9).
One line: the digits of the incremented number, space-separated.
Example 1
Input
3 1 2 3
Expected
1 2 4
Explanation
123 + 1 = 124, so the digits are 1 2 4.
Example 2
Input
3 9 9 9
Expected
1 0 0 0
Explanation
999 + 1 = 1000, which needs a new leading digit: 1 0 0 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →