Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5594 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 783 |

@Manikanta punnam | 605 |

@sriramgoparaju99 | 590 |

@rdakka | 538 |

@praveenbgp6 | 529 |

@prankursharma31 | 518 |

@yashkaril4 | 517 |

@purohitmn02 | 467 |

@sonamnigam1999 | 443 |

@sonamkumari63928 | 441 |

@shubhamstudent5 | 433 |

Complete Leaderboard |

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:**

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

**Example 2:**

**Input**:
N = 3
arr[] = {9,9,9}
**Output**:
1 0 0 0
**Explanation**:
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)

**Constraints:**

1 <= N <= 10^{5}

0 <= arr_{i} <= 9

Login 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?

Yes
Plus One

...