DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Plus One

**Problem Statement:** You are given a large integer represented as an integer array `digits`, where each `digits[i]` is the `i`th digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. Increment the large integer by one and return the resulting array of digits. **Hint / Expected Approach:** Carry propagation from end **Edge Cases to Consider:** - (1) All nines [9,9,9] - (2) Single digit 9 - (3) No carry needed

Examples

Example 1
Input: [1,2,3]
Output: [1,2,4]
Example 2
Input: [4,3,2,1]
Output: [4,3,2,2]
Example 3
Input: [9]
Output: [1,0]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪All nines [9,9,9]
  • ▪Single digit 9
  • ▪No carry needed
Frequently Asked At
GoogleAmazonMicrosoftTCS