Implement Plus One
Company: Coinbase
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Given an integer represented as an array of digits `digits`, where the most significant digit comes first, return the array representing the integer plus one.
Assume:
- `digits` contains only values from `0` to `9`
- the integer has no leading zeros unless it is exactly zero
Examples:
- `[1, 2, 3] -> [1, 2, 4]`
- `[4, 3, 2, 1] -> [4, 3, 2, 2]`
- `[9, 9, 9] -> [1, 0, 0, 0]`
Implement the solution in Python. Aim for `O(n)` time and `O(1)` extra space apart from the returned array.
Quick Answer: This question evaluates proficiency in array manipulation, elementary arithmetic operations such as carry propagation, and careful handling of edge cases while meeting time and space complexity constraints.