Skip to main content

7. Plus One

easyAsked at Snowflake

Given a big integer represented as a digit array, add one. Snowflake uses this to test edge-case rigor — the carry propagation is the same shape as overflow handling in their NUMBER(38,0) arithmetic kernels.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Snowflake loops.

  • Glassdoor (2025-Q4)Snowflake numerics-team uses this as a warm-up before fixed-point arithmetic problems.
  • LeetCode Discuss (2025-09)Reported at Snowflake SDE-I phone screens.

Problem

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. The large integer does not contain any leading 0's. Increment the large integer by one and return the resulting array of digits.

Constraints

  • 1 <= digits.length <= 100
  • 0 <= digits[i] <= 9
  • digits does not contain any leading 0's.

Examples

Example 1

Input
digits = [1,2,3]
Output
[1,2,4]

Explanation: 123 + 1 = 124.

Example 2

Input
digits = [9]
Output
[1,0]

Example 3

Input
digits = [9,9,9]
Output
[1,0,0,0]

Approaches

1. Convert to number, add, convert back

Join digits to a string, parse as integer, add one, split back.

Time
O(n)
Space
O(n)
function plusOne(digits) {
  const n = BigInt(digits.join('')) + 1n;
  return n.toString().split('').map(Number);
}

Tradeoff: Works in JS thanks to BigInt, but defeats the purpose — Snowflake wants to see carry logic.

2. Right-to-left carry propagation (optimal)

Walk from least significant digit. If digit < 9, increment and return. Otherwise set to 0 and continue. If you fall off the start, prepend 1.

Time
O(n)
Space
O(1) (or O(n) on the overflow case)
function plusOne(digits) {
  for (let i = digits.length - 1; i >= 0; i--) {
    if (digits[i] < 9) {
      digits[i]++;
      return digits;
    }
    digits[i] = 0;
  }
  // All nines case
  return [1, ...digits];
}

Tradeoff: O(1) amortized when no overflow; O(n) only on the all-nines case. This is exactly how fixed-point arithmetic increments work in a database engine.

Snowflake-specific tips

Snowflake interviewers want to see you handle the all-nines case explicitly and not just 'add one and modulo 10' through the whole array. Bonus signal: discuss precision — Snowflake's NUMBER(38,0) supports 38 digits, and you'd implement increment exactly this way under the hood.

Common mistakes

  • Forgetting the all-nines case (e.g., [9,9,9] -> [1,0,0,0]) and returning [0,0,0].
  • Looping left-to-right and getting carry direction wrong.
  • Trying to use parseInt on long inputs — overflows at 16 digits in regular numbers.

Follow-up questions

An interviewer at Snowflake may pivot to one of these next:

  • Add two numbers represented as digit arrays (LC 989, Add to Array-Form).
  • Multiply Strings (LC 43).
  • What if digits are stored in a linked list?

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why right-to-left?

Carry only propagates from less significant to more significant digits. Walking right-to-left lets you stop the moment you find a digit that doesn't carry.

Why does Snowflake care about this?

NUMBER(p,s) arithmetic must avoid overflow and preserve precision. The increment, addition, and multiplication kernels all use this digit-by-digit carry pattern under the hood.

Practice these live with InterviewChamp.AI

Drill Plus One and other Snowflake interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →