Increment the large integer by one and return the resulting array of digits.
Example:
Input: digits = [1,2,3]
Output: [1,2,4]
Explanation: The ar...
For further actions, you may consider blocking this person and/or reporting abuse
It’s important to remember that this is an interview question and they will press you on different ways to achieve this. Even if you use a BigInt and solve the question, depending on the level they will ask you to solve it without BigInt as well as explain the time and space complexity of your answer. So knowing how to do it with a loop and without string manipulation will likely be very important.
another classic way
Cool one. Thanks. But this fails in case of large arrays like..
[3,4,5,6,7,8,,1,2,3,1,2,3,4,5,6,7,8,8,4,3,2,5,6,7].
you wrote integer...sorry
Number conversion fails in case of large numbers. But, yeah that is worst case. Cool one Alex. Much more simplified.
Otherwise, we can use recursion:
I love recursion for cases like this, because it makes the different branches really obvious.
plusOne([3,4,5,6,7,8,1,2,3,1,2,3,4,5,6,7,8,8,4,3,2,5,6,9,3,3,3,3,9])
….
missing convert...
Good. One. I think each time array needs to be converted completely even though the last digit is 9 or not.
any how, its simplified thanks.