15% off all plans & roadmaps Use code
See plansLeetCode 66 · Solution & editorial
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.
Plus One is a Array/Matrix Manipulation Patterns problem, in the Plus One (Handling Carry) subpattern. The pattern covers in-place operations, hashing, prefix sums, spiral traversal, and cyclic sort
Learn to handle carry operations when adding one to a number represented as an array of digits.
The reference solution runs in O(n) time and O(1) space.
Plus One has been reported in interviews at ByteDance, Facebook, Adobe, Amazon, Spotify, Google.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Plus One is a Array/Matrix Manipulation Patterns problem, in the Plus One (Handling Carry) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.