Add Large Numbers Stored as Lists
Updated
Problem statement
Two nonnegative integers are represented by arrays of decimal digits in most-significant-first order.
Add the two numbers and return their sum in the same representation. Each element is one digit from 0 through 9. The only representation with a leading zero is the one-digit number [0].
The inputs may be much longer than any built-in integer type, so perform the addition digit by digit.
Function
addLargeNumbers(a: int[], b: int[]) → int[]Examples
Example 1
a = [9,9,9]b = [1]return = [1,0,0,0]The carry propagates through all three digits.
Example 2
a = [1,2,3,4]b = [5,6,7]return = [1,8,0,1]The represented values are 1234 and 567, whose sum is 1801.
Constraints
1 <= a.length, b.length <= 100000.- Every element is an integer from
0through9. - Neither input has a leading zero unless its length is
1.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
- Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
- Mini-Batch Data LoaderOpenAI · PHONE SCREENOpenAI interview questions
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Deterministic K-Means AssignmentsLyft · PHONE SCREENLyft interview questions
- Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions