Merge Two Sorted Linked Lists
Updated
Problem statement
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) → ListNodeExamples
Example 1
list1 = [1,2,4]list2 = [1,3,4]return = [1,1,2,3,4,4]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]Relink all original nodes in nondecreasing order, taking the first list first on a tie.
Example 3
list1 = []list2 = []return = []Relink all original nodes in nondecreasing order, taking the first list first on a tie.
Constraints
0 <= list1.length <= 50and0 <= 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)