FastPrepAdd Two Numbers
Problems/Add Two Numbers

Add Two Numbers

Zillow logoZillow● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported at Zillow by an ML Engineer candidate in the United States who interviewed in February 2020 and did not get an offer. The interview was a phone round run by a Zillow software engineer. The engineer described his own job, asked what the candidate hoped to learn and what interested them, and asked about the candidate's past projects. The report lists one coding question: how to add two numbers that are kept in linked lists.

The report does not say in which order the digits sit in the lists, how the lists reach the function, or how long the numbers can be. These choices are ours, taken from the well-known version of this task: the function addTwoNumbers gets the first node of each list, each node holds one digit with the ones digit first, neither number has leading zeros except the number 0, and the sum comes back as a new list in the same order. Each list has 1 to 100 nodes; this limit is ours as well.

Our version is about 90% the same as the reported question.

You are given two non-empty linked lists, l1 and l2. Each list stores a non-negative integer, one decimal digit per node. The digits are stored in reverse order: the first node holds the ones digit, the second node holds the tens digit, and so on.

Add the two numbers and return the sum as a new linked list in the same format: one digit per node, ones digit first.

Neither number has leading zeros, except the number 0 itself, which is a list with one node holding 0.

The examples write each list as its node values from the first node to the last.

Function

addTwoNumbers(l1: ListNode, l2: ListNode) → ListNode

Examples

Example 1

l1 = [4,8,6]l2 = [7,5]return = [1,4,7]
l1
486
l2
75
return
147

Read from the last node back to the first, l1 holds 684 and l2 holds 57. Their sum is 741, so the answer lists its digits ones digit first: [1,4,7]. Digit by digit: 4 + 7 = 11 gives digit 1 and a carry of 1; 8 + 5 + 1 = 14 gives 4 and a carry of 1; l2 has no third node, so the last step is 6 + 1 = 7, which gives 7.

Example 2

l1 = [9,9]l2 = [3]return = [2,0,1]
l1
99
l2
3
return
201

l1 holds 99 and l2 holds 3, and 99 + 3 = 102. The first position gives 9 + 3 = 12: digit 2 and a carry of 1. l2 has no second node, so the second position gives 9 + 1 = 10: digit 0 and a carry of 1. The carry left after the last position becomes a third node holding 1.

Example 3

l1 = [0]l2 = [0]return = [0]
l1
0
l2
0
return
0

Both lists hold the number 0, and 0 + 0 = 0. The sum is written as one node holding 0.

Constraints

  • Each list has between 1 and 100 nodes.
  • 0 <= Node.val <= 9
  • Neither list has leading zeros: its last node is not 0 unless the list is [0].

More Zillow Phone Screen questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Time Based Key-Value StorePHONE SCREEN · Seen Feb 2024
  • Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Jump GamePHONE SCREEN · Seen Dec 2022
  • Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • Two Sum: All PairsPHONE SCREEN · Seen Nov 2022
  • Employee Free TimePHONE SCREEN · Seen Oct 2022
  • First Unique Character in a StringPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Add Two Numbers IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Add Forward Linked-List Numbers Using RecursionPeopleStrong · PHONE SCREENPeopleStrong 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 Two Numbers Stored as Linked ListsCapital One · ONSITE INTERVIEWCapital One interview questions
  • Add NumbersCisco · OACisco interview questions
  • Binary Linked List to DecimalJP Morgan Chase · OAJP Morgan Chase interview questions
  • Path Between Two Nodes of a Fibonacci TreeDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        // Write your code here.
    }
}
Checking account…