Add Numbers
Updated
Problem statement
You are given two lists of digits, list1 and list2. Each list stands for a non-negative whole number.
The digits are stored in reverse order. The first element is the ones digit, the second element is the tens digit, and so on. For example, [2, 4, 6] stands for the number 642.
Add the two numbers. Return the digits of the sum as a list, also in reverse order.
Function
addNumbers(list1: List<Integer>, list2: List<Integer>) → List<Integer>Examples
Example 1
list1 = [2, 4, 6]list2 = [8, 0, 9]return = [0, 5, 5, 1]The given lists are [2,4,6], [8,0,9], so the two numbers are '642' and '908'. The sum of both the numbers is 642+908=1550. So the output is [0, 5, 5, 1].
Constraints
1 ≤ list1.length ≤ 1001 ≤ list2.length ≤ 1000 ≤ list1[i], list2[i] ≤ 9- A list never ends with an extra
0, except the list[0]for the number zero.
More Cisco interview questions
- Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
- Find Unique ElementsPHONE SCREEN · Seen Nov 2026
- First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
- Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a StringPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
- Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
- Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Binary Linked List to DecimalJP Morgan Chase · OAJP Morgan Chase interview questions
- Add One to a Number Stored in a Linked ListExpedia · ONSITE INTERVIEWExpedia interview questions
- Add Two Numbers IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Subtract Forward-Order Linked-List NumbersMicrosoft · ONSITE INTERVIEWMicrosoft 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 Two NumbersZillow · PHONE SCREENZillow interview questions
- Add Two Numbers Stored as Linked ListsCapital One · ONSITE INTERVIEWCapital One interview questions
- Last Digit of the Ways to Split Traders Between Two OfficesAkuna Capital · OAAkuna Capital interview questions
- Counting Cows by Their LegsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions