FastPrepMerge Two Sorted Lists
Problems/Merge Two Sorted Lists

Merge Two Sorted Lists

The Walt Disney Company logoThe Walt Disney Company● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report lists "Merge Two Sorted List" among collected past interview questions.

The report does not give a signature or bounds. Here, the two lists have at most 250 nodes each; empty lists are allowed, duplicates are kept, and existing nodes are linked into sorted order.

The judged task matches the report at about 85%.

Given the heads of two singly linked lists sorted in nondecreasing order, merge them into one sorted list by linking their existing nodes. Return its head and keep every value, including duplicates.

The input lists are acyclic and share no nodes. Each displayed array lists node values in order; [] means a null head.

Function

mergeTwoLists(list1: ListNode, list2: ListNode) → ListNode

Examples

Example 1

list1 = [0,3,8]list2 = [1,3,9]return = [0,1,3,3,8,9]

Taking the smaller remaining head gives [0,1,3,3,8,9]. Both nodes with value three are retained.

Example 2

list1 = []list2 = [-2,5]return = [-2,5]

The first list is empty, so the second list is the whole result: [-2,5].

Constraints

  • 0 <= list1.length <= 250
  • 0 <= list2.length <= 250
  • -1000000 <= list1[i] <= 1000000
  • -1000000 <= list2[i] <= 1000000
  • Both lists are sorted in nondecreasing order.

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company 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 mergeTwoLists(ListNode list1, ListNode list2) {
        // Write your code here
    }
}
Checking account…