Add Two Numbers Stored as Linked Lists
Updated
Problem statement
Read each of l1 and l2 from the head to get a number: the head is its leading digit and every following node is the next digit. So 3 → 0 → 8 means 308, and no number here is negative.
Add the two numbers and give back the total, written the same way as a new list. Write no extra zeros at the front; a total of zero is one node holding 0.
Function
addTwoNumbers(l1: ListNode, l2: ListNode) → ListNodeExamples
Example 1
l1 = [3,0,8]l2 = [9,4]return = [4,0,2]The lists stand for 308 and 94. 308 + 94 = 402, which becomes 4 → 0 → 2.
Example 2
l1 = [6]l2 = [4,9,9,6]return = [5,0,0,2]6 + 4996 = 5002. The carry from the last digit moves through two 9s before it stops.
Example 3
l1 = [8,8]l2 = [1,2]return = [1,0,0]88 + 12 = 100. The total has one more digit than either number, so the answer list is longer than both inputs.
Constraints
- Each list has between
1and1000nodes. 0 <= Node.val <= 9- No list has a leading zero, except a list that is the single node
0.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
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
- Add Two Numbers Stored in Reversed ListsExpedia · ONSITE INTERVIEWExpedia interview questions
- Add Numbers Stored in Four-Digit ChunksZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
- Add Forward Linked-List Numbers Using RecursionPeopleStrong · PHONE SCREENPeopleStrong interview questions
- Add NumbersCisco · OACisco interview questions
- Binary Linked List to DecimalJP Morgan Chase · OAJP Morgan Chase interview questions
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Reverse a Sublist of a Linked ListSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
Capital One interview experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences
- Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)