Plus One
Easy Accuracy: 50.09% Submissions: 28087 Points: 2

Given a non-negative number represented as a list of digits, add 1 to the number (increment the number represented by the digits). The digits are stored such that the most significant digit is first element of array.

Example 1:

N = 3
arr[] = {1, 2, 4}
1 2 5
124+1 = 125, and so the Output

Example 2:

N = 3
arr[] = {9,9,9}
1 0 0 0
999+1 = 1000, and so the output

Your Task:
You don't need to read input or print anything. You only need to complete the function increment() that takes an integer N, and an array arr of size N as input and returns a list of integers denoting the new number which we get after adding one to the number denoted by the array arr.

Expected Time Complexity:  O(N)
Expected Auxilliary Space: O(1)


1 <= N <= 105
0 <= arri <= 9

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Plus One

Output Window