Skip to main content

7. Plus One

easyAsked at Plaid

Increment a non-negative integer represented as an array of digits. Plaid asks this because incrementing big-integer balances (cents stored as digit arrays) without overflow is a real ledger primitive.

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

Source citations

Public interview reports confirming this problem appears in Plaid loops.

  • Glassdoor (2025)Plaid OA warm-up paired with a financial-precision follow-up.
  • LeetCode Discuss (2026)Reported as Plaid intro.

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 zeros. 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 zeros.

Examples

Example 1

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

Example 2

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

Approaches

1. Convert to BigInt, add, convert back

Join, BigInt(), add 1, split back to digits.

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

Tradeoff: Works but dodges the algorithm. Plaid wants to see manual carry handling because that's what the ledger code does.

2. Right-to-left carry propagation

Walk from the least significant digit. Add one; if it overflows to 10, set to 0 and carry; otherwise we're done. If we exit the loop still carrying, 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: Returns early on the first non-9. The [1, ...digits] handles the all-nines case cleanly. This is the textbook ledger-carry pattern.

Plaid-specific tips

Plaid grades this on whether you handle the all-nines carry cleanly. Bonus signal: mention you'd write the same loop with bigint deltas in cents because floating-point round-trips lose precision on balances. Articulate the early-return optimization for the common case (no carry).

Common mistakes

  • Iterating left-to-right — gets the carry direction backward.
  • Forgetting the all-nines case — array length grows by 1.
  • Using parseInt(digits.join('')) — overflows for 100-digit inputs.

Follow-up questions

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

  • Add two numbers represented as digit arrays (LC 989).
  • Subtract one — handles negative results and trailing zeros.
  • Increment a decimal stored as fixed-point cents — same loop, different base case.

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 not use parseInt or Number?

Integer precision tops out at 2^53. A 100-digit number overflows. BigInt works but dodges the algorithm Plaid wants to see.

Why the early return inside the loop?

The common case is no carry past the first digit. Returning early avoids touching the rest of the array — important when digits.length is large.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →