Back to questions
We're trying to create a digital clone of DJ Khaled. No fancy AI or alorithms needed.
Just take a number and add another one:
More specifically, you are given an integer array , where each is the ith digit of positive whole number. It is ordered from most significant to least significant digit.
Return an array of digits of the number after adding another one to the input.
Input:
Output:
Input:
Output:
Let's break the problem down into an easier version:
What if the last digit is not ? In that case, all we need to do is add to the last digit and return the updated array.
Here's how it works if we guarantee that the last digit is not :
But what happens when the last digit is ?
When the last digit is , adding turns it into , and we carry the over to the previous digit.
However, there's a catch: multiple digits might be , meaning we need to keep carrying the leftward until we find a digit that's not .
Here's the full code: