Merge Two Descending Linked Lists
Updated
Problem statement
Given the heads of two singly linked lists listA and listB, each sorted in nonincreasing order, merge their nodes into one linked list that is also sorted in nonincreasing order.
Preserve every node value, including duplicates. Either input list may be empty.
Function
mergeDescendingLists(listA: ListNode, listB: ListNode) → ListNodeExamples
Example 1
listA = [9,7,3]listB = [10,8,7,1]return = [10,9,8,7,7,3,1]From listAFrom listB
At each step, append the larger current head. Both nodes with value 7 remain in the merged list.
Example 2
listA = []listB = [5,5,2]return = [5,5,2]When one input is empty, the other list is already the complete descending result.
Example 3
listA = [4,2]listB = [3]return = [4,3,2]From listAFrom listB
The head 4 is followed by 3, then the remaining node 2.
Constraints
- The two lists contain at most
100000nodes in total. - Every node value is a signed 32-bit integer.
- Each input list is sorted in nonincreasing order.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
- Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
- Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions
- Reverse a Singly Linked ListGEP · ONSITE INTERVIEW
- Merge Two Sorted Linked ListsApple · ONSITE INTERVIEWApple interview questions
- Reverse Linked ListThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Detect a Linked-List CycleGoogle · ONSITE INTERVIEWGoogle interview questions
- Detect a Cycle in a Linked ListPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Reverse a Singly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions