top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Add One To Number: Interviewbit Solution

Sep 1, 2020
1 min read

Updated: Sep 8, 2020


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:


1 Comment


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.

Like
bottom of page