Skip to main content

7. Plus One

easyAsked at PayPal

Given a non-empty array of digits representing a large integer, increment it by one. PayPal asks this to test arbitrary-precision arithmetic awareness — currency amounts at scale exceed 64-bit, and you cannot lose a cent to overflow.

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

Source citations

Public interview reports confirming this problem appears in PayPal loops.

  • Glassdoor (2025-12)PayPal SDE-1 warm-up; financial-precision angle highlighted.

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 = [4,3,2,1]
Output
[4,3,2,2]

Example 3

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

Approaches

1. Convert to BigInt and back

Join digits to a string, BigInt, add 1, split.

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

Tradeoff: Works but obscures the carry mechanics. Some PayPal interviewers ban it because financial code shouldn't depend on bigint coercion.

2. Carry propagation in-place (optimal)

Iterate from the last digit. Add carry. If digit < 10, return. Else set to 0 and continue. If carry remains, prepend 1.

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

Tradeoff: Hand-rolled carry — exactly what a financial-precision codebase needs. Same pattern PayPal uses for multi-precision currency rolls (e.g., $999.99 → $1000.00).

PayPal-specific tips

PayPal grades you on whether you handle the all-9s case ([9,9,9] → [1,0,0,0]) cleanly. Bonus signal: mention this is a baby BigDecimal — at PayPal real-money systems use arbitrary-precision libraries (Java BigDecimal, Python decimal) precisely because IEEE-754 floats lose pennies.

Common mistakes

  • Forgetting to prepend 1 on all-9s — returns [0,0,0] instead of [1,0,0,0].
  • Using parseInt on a 100-digit array — overflows JS Number precision past 15 digits.
  • Using array.push then reverse — wastes a pass and confuses the reader.

Follow-up questions

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

  • Add two numbers represented as digit arrays (LC 989, LC 415).
  • Multiply two large numbers as 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 not just parseInt and ++?

JS Number is 64-bit float; integer precision dies past 2^53. Currency at PayPal scale can exceed that, and you cannot lose a cent. Always assume arbitrary precision.

Is unshift O(n)?

Yes, but it only happens in the all-9s case and only once. Amortized cost stays O(n) overall.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →