Add Forward Linked-List Numbers Using Recursion
Updated
Problem statement
Two nonnegative decimal integers are stored in singly linked lists first and second, with the most significant digit first. Each node contains one digit. Use recursion to add the digits and return a new linked list representing their sum in the same forward order.
For this exercise, assume both inputs are nonempty and may contain leading zeros. Normalize the output by removing leading zeros, except that zero itself is represented by one node containing 0. Preserve both input lists. Lists are serialized as arrays in head-to-tail order.
Function
addListNumbers(first: ListNode, second: ListNode) → ListNodeExamples
Example 1
first = [7,2,4,3]second = [5,6,4]return = [7,8,0,7]The lists represent 7243 and 564; their sum is 7807.
Example 2
first = [0,0,9]second = [0,1]return = [1,0]Leading zeros do not change 9 + 1 = 10. The output contains no extra leading zeros.
Constraints
- For this exercise, assume each list has 1 to 1000 nodes.
- Every node value is an integer digit from 0 through 9.
- Both lists are finite and acyclic.
More PeopleStrong Phone Screen questions
- Reverse Linked-List Nodes in Groups of KOA · PHONE SCREEN · Seen Mar 2026
- Level of the Minimum-Sum SubtreePHONE SCREEN · Seen Jan 2026
- Ceiling Value in a Sorted ArrayPHONE SCREEN · Seen Sep 2025
- Maximum Employee Salary for a CompanyPHONE SCREEN · Seen Sep 2025
- Valid ParenthesesPHONE SCREEN · Seen Sep 2025
- Number of ProvincesPHONE SCREEN · Seen May 2025
- Shortest Subarray with an Exact Target SumPHONE SCREEN · Seen May 2025
- Running Median of a StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2021
- Build an Expression Tree from PostfixPHONE SCREEN · Seen Oct 2021
- Maximum Score from Deleting Neighboring ValuesPHONE SCREEN · Seen Oct 2021
Similar questions at other companies
- Add Two Numbers IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Subtract Forward-Order Linked-List NumbersMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Basic Calculator IISnap Inc. · PHONE SCREENSnap Inc. interview questions
- Simplify a Nested Variable ExpressionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Turn a BST Into a Sorted Doubly Linked ListAdobe · PHONE SCREENAdobe interview questions
- Min StackCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- Evaluate Reverse Polish NotationCoalition · PHONE SCREEN
- Evaluate Arithmetic with Operator PrecedenceRoblox · PHONE SCREENRoblox interview questions
- Simplify a Formula with Known and Unknown VariablesBetter.com · PHONE SCREEN
- Evaluate Parenthesized Addition and SubtractionAtlassian · PHONE SCREENAtlassian interview questions