Merge Two Sorted Linked Lists
Updated
Problem statement
You are given the heads of two singly linked lists, list1 and list2. Each list is already sorted from smallest to largest value (equal values may repeat).
Join all nodes of both lists into one list that is also sorted from smallest to largest, by changing the links between the existing nodes, and return its head. Keep every node, including repeated values.
Function
mergeTwoSortedLists(list1: ListNode, list2: ListNode) → ListNodeExamples
Example 1
list1 = [1,4,4,9]list2 = [2,4,10]return = [1,2,4,4,4,9,10]From list1From list2
Take the smaller front value each time: 1, 2, then the three 4s (two from list1, one from list2), then 9 and 10.
Example 2
list1 = []list2 = [-3,0]return = [-3,0]list1 is empty, so the answer is list2.
Example 3
list1 = [5,6,7]list2 = [1,2]return = [1,2,5,6,7]From list1From list2
Every value in list2 is smaller, so its nodes come first, followed by all of list1.
Constraints
- Each list has between
0and1000nodes. -1000 <= node.val <= 1000- Each list is sorted in non-decreasing order.
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Middle of a Linked ListCisco · PHONE SCREENCisco 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
- Linked List Palindrome in Constant SpaceNVIDIA · PHONE SCREENNVIDIA interview questions
- Reverse a Singly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Merge Two Sorted Linked ListsExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions