Increment Digit Array
Company: Coinbase
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Given a non-empty array of digits representing a non-negative integer, add one to the integer and return the resulting array of digits.
Assumptions:
- The most significant digit is at index 0.
- Each element is an integer from 0 to 9.
- The input has no leading zeros unless the number itself is 0.
- Do not convert the entire array to a built-in big integer type.
Examples:
- `[1,2,3] -> [1,2,4]`
- `[4,3,2,1] -> [4,3,2,2]`
- `[9] -> [1,0]`
- `[9,9,9] -> [1,0,0,0]`
Write an efficient Python solution and state its time and space complexity.
Quick Answer: This question evaluates a candidate's competency in array manipulation and elementary arithmetic on digit sequences, including carry propagation and handling edge cases when incrementing a number represented as a digit array in the Coding & Algorithms domain.