PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in array manipulation, elementary arithmetic operations such as carry propagation, and careful handling of edge cases while meeting time and space complexity constraints.

  • medium
  • Coinbase
  • Coding & Algorithms
  • Data Scientist

Implement Plus One

Company: Coinbase

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given an integer represented as an array of digits `digits`, where the most significant digit comes first, return the array representing the integer plus one. Assume: - `digits` contains only values from `0` to `9` - the integer has no leading zeros unless it is exactly zero Examples: - `[1, 2, 3] -> [1, 2, 4]` - `[4, 3, 2, 1] -> [4, 3, 2, 2]` - `[9, 9, 9] -> [1, 0, 0, 0]` Implement the solution in Python. Aim for `O(n)` time and `O(1)` extra space apart from the returned array.

Quick Answer: This question evaluates proficiency in array manipulation, elementary arithmetic operations such as carry propagation, and careful handling of edge cases while meeting time and space complexity constraints.

Given an integer represented as an array of digits `digits`, where the most significant digit comes first, return the array representing the integer plus one. Assume: - `digits` contains only values from `0` to `9` - the integer has no leading zeros unless it is exactly zero Examples: - `[1, 2, 3] -> [1, 2, 4]` - `[4, 3, 2, 1] -> [4, 3, 2, 2]` - `[9, 9, 9] -> [1, 0, 0, 0]` Aim for `O(n)` time and `O(1)` extra space apart from the returned array.

Constraints

  • 1 <= digits.length
  • 0 <= digits[i] <= 9
  • digits has no leading zeros unless the integer is exactly 0

Examples

Input: ([1, 2, 3],)

Expected Output: [1, 2, 4]

Explanation: No carry needed; the last digit 3 becomes 4.

Input: ([4, 3, 2, 1],)

Expected Output: [4, 3, 2, 2]

Explanation: The last digit 1 becomes 2; no carry propagates.

Input: ([9, 9, 9],)

Expected Output: [1, 0, 0, 0]

Explanation: Every digit is 9, so each becomes 0 and the carry propagates past the front, prepending a new leading 1.

Input: ([0],)

Expected Output: [1]

Explanation: Single zero plus one is one.

Input: ([9],)

Expected Output: [1, 0]

Explanation: Single nine carries out, producing a two-digit result [1, 0].

Input: ([1, 9, 9],)

Expected Output: [2, 0, 0]

Explanation: The two trailing nines roll to zero and the carry increments the leading 1 to 2.

Hints

  1. Adding one only affects the trailing digits while there is a carry. Walk the array from the least significant (rightmost) digit toward the most significant.
  2. If a digit is less than 9, increment it and return immediately — no further carry is possible.
  3. If a digit is 9, set it to 0 and continue the carry leftward. If the carry propagates past the first digit (all nines), prepend a 1 to the result, e.g. [9,9,9] -> [1,0,0,0].
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement a Coin-Constrained Jump Strategy - Coinbase (hard)
  • Implement an In-Memory Database - Coinbase (hard)
  • Implement Game Physics and Block Mining - Coinbase (hard)
  • Compute Total Manual Distance - Coinbase (medium)
  • Implement a Flappy Bird Jump Agent - Coinbase