Skip to main content

8. Plus One

easyAsked at Coinbase

Increment a big integer represented as a digit array by one. Coinbase uses this as a warm-up before the inevitable BigInt and precision-handling follow-ups.

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

Source citations

Public interview reports confirming this problem appears in Coinbase loops.

  • Glassdoor (2026-Q1)Coinbase warm-up for arbitrary-precision arithmetic discussion.

Problem

You are given a large integer represented as an integer array digits, where each digits[i] is the ith 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]

Example 2

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

Example 3

Input
digits = [0]
Output
[1]

Approaches

1. Convert via Number, add 1, convert back

Join digits, parseFloat or Number, add 1, split back to array.

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

Tradeoff: Breaks for digits.length > 16 — overflows Number.MAX_SAFE_INTEGER and you get rounding. NEVER use floats for monetary values.

2. Right-to-left carry propagation

Walk from the rightmost digit. Add 1, propagate carry. If carry persists past the leftmost digit, prepend a 1.

Time
O(n)
Space
O(1) extra (output is O(n))
function plusOne(digits) {
  for (let i = digits.length - 1; i >= 0; i--) {
    if (digits[i] < 9) {
      digits[i]++;
      return digits;
    }
    digits[i] = 0;
  }
  return [1, ...digits];
}

Tradeoff: O(n) worst case (all 9s), but most inputs terminate at the first non-9. No precision loss because we never go through Number.

Coinbase-specific tips

Coinbase grades whether you spot the Number-overflow trap. They specifically care because crypto amounts routinely exceed 2^53 — saying out loud 'I won't use Number because amounts here can be 10^18 wei' wins the follow-up before it's asked. Mention BigInt or string-based arithmetic.

Common mistakes

  • Using Number(digits.join('')) — silently corrupts inputs longer than ~16 digits.
  • Forgetting the all-9s edge case — [9,9] should become [1,0,0], not [0,0].
  • Mutating the input when the caller expected a new array — clarify ownership.

Follow-up questions

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

  • Add two big-integer arrays (LC 415 generalized).
  • Subtract one — handles borrow propagation.
  • Multiply by k — long multiplication on digit arrays.

Solve it now

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

Output

Press Run or Cmd+Enter to execute

FAQ

When should I use BigInt vs digit arrays?

BigInt for arbitrary-precision math you'll do many operations on. Digit arrays when the input is already in that form and conversion would be wasted work. For crypto amounts, prefer BigInt or fixed-point integers.

Why does Number break here?

JS Number is IEEE-754 double. Past 2^53 (≈9×10^15), consecutive integers can't all be represented — adding 1 may round to itself or skip a value. That's a guaranteed ledger bug.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →