Given an array which represents a number, add 1 to the array. Suppose an array contain elements [1, 2, 3, 4] then the array represents decimal number 1234 and hence adding 1 to this would result 1235. So new array will be [1, 2, 3, 5].
Input : [1, 2, 3, 4] Output : [1, 2, 3, 5] Input : [1, 2, 9, 9] Output : [1, 3, 0, 0] Input: [9, 9, 9, 9] Output: [1, 0, 0, 0, 0]
1. Add 1 to the last element of the array, if it is less than 9.
2. If it is 9, then make it 0 and recurse for the remaining element of the array.
1, 9, 4, 0
- Adding one to number represented as array of digits
- Sum of two numbers where one number is represented as array of digits
- Check whether a large number represented as array is divisible by Y
- Check in binary array the number represented by a subarray is odd or even
- Minimum cost to connect weighted nodes represented as array
- Find the smallest positive integer value that cannot be represented as sum of any subset of a given array
- Iterative approach to print all combinations of an Array
- Iterative approach to print all permutations of an Array
- Square of large number represented as String
- Find the smallest positive number which can not be represented by given digits
- Program for average of an array (Iterative and Recursive)
- Construct Binary Tree from given Parent Array representation | Iterative Approach
- Program to check if an array is sorted or not (Iterative and Recursive)
- Recursive Programs to find Minimum and Maximum elements of array
- Recursive program to find all Indices of a Number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Smitha Dinesh Semwal