FastPrepMerge Two Sorted Linked Lists
Problems/Merge Two Sorted Linked Lists

Merge Two Sorted Linked Lists

Expedia logoExpedia● EasyNEW GRADFULLTIMEINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The task of splicing nodes together matches the linked report at about 98%. We chose the limits and the order for equal values.

Merge two disjoint, acyclic linked lists that are sorted in nondecreasing order. Reuse and relink the original nodes, keeping every node exactly once, and return the merged head.

Either list may be empty. When current values are equal, take the node from list1 first. Preserve the order within each input list.

Function

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

Examples

Example 1

list1 = [1,2,4]list2 = [1,3,4]return = [1,1,2,3,4,4]
list1
124
list2
134
return
112344
From list1From list2

Relink all original nodes in nondecreasing order, taking the first list first on a tie.

Example 2

list1 = []list2 = [0]return = [0]
list1
empty
list2
0
→
return
0

Relink all original nodes in nondecreasing order, taking the first list first on a tie.

Example 3

list1 = []list2 = []return = []
list1
empty
list2
empty
return
empty

Relink all original nodes in nondecreasing order, taking the first list first on a tie.

Constraints

  • 0 <= list1.length <= 50 and 0 <= list2.length <= 50.
  • -100 <= node.val <= 100.
  • Both lists are sorted in nondecreasing order and have no shared nodes.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Middle of a Linked ListCisco · PHONE SCREENCisco interview questions
  • Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
  • Merge Two Sorted ListsIBM · PHONE SCREENIBM interview questions
  • Count Nodes in a ChainApple · PHONE SCREENApple interview questions
  • Detect a Cycle in a Linked ListSalesforce · PHONE SCREENSalesforce interview questions
  • Find the Intersection Node of Two Linked ListsVisa · PHONE SCREENVisa interview questions
  • Reverse a Linked ListMygate · PHONE SCREENMygate interview questions
  • Find the Intersection Node of Two Linked ListsLinkedIn · PHONE SCREENLinkedIn interview questions
  • Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
  • Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions

Interview reports that mention this question

  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
  • Expedia New Grad SDE Oldest Loops: 4 Experiences (Part 3 of 3)
  • Expedia New Grad SDE Interviews: 20 Experiences (Part 1 of 3)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
All Expedia interview questionsSee Expedia 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…