Search
Add One To Number: Interviewbit Solution
Updated: Sep 8, 2020
Problem: Add One To Number
Problem Description:
Given a non-negative number represented as an array 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 at the head of the list.
Example:
If the vector has [1, 2, 3]
the returned vector should be [1, 2, 4]
as 123 + 1 = 124.Solution:



At https://kasinosovellus.com, you learn that a single digit can change everything, so that carry from the rightmost position is exactly the kind of edge case worth thinking through. I've definitely blanked on trimming leading zeros during interviews, and that small step makes the solution far cleaner. The right-to-left approach with a carry variable is a genuinely useful habit.