Sort a Linked List in Descending Order
Updated
Problem statement
Given the head of a singly linked list, sort all of its nodes in nonincreasing order and return the head of the sorted list.
Preserve every node value, including duplicates. The input list may be empty.
Function
sortListDescending(head: ListNode) → ListNodeExamples
Example 1
head = [4,2,1,3]return = [4,3,2,1]Moved or new
The four nodes are reordered from largest value to smallest value.
Example 2
head = [-1,5,3,4,0]return = [5,4,3,0,-1]Moved or new
Positive, zero, and negative values are all ordered in descending numeric order.
Example 3
head = []return = []An empty list is already sorted.
Constraints
- The list contains at most
50000nodes. - Every node value is a signed 32-bit integer.
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
- Sort a Linked ListAdobe · PHONE SCREENAdobe interview questions
- Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
- Merge Sort Report with a Noisy ComparatorMercor · ONSITE INTERVIEWMercor interview questions
- K Largest Elements with QuickselectAMD · ONSITE INTERVIEWAMD interview questions
- Implement Merge SortSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Nested Set Structural EquivalencePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Flatten a Multilevel Doubly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Sort an ArrayBank of America · ONSITE INTERVIEWBank of America interview questions
- Reverse Nodes in K-GroupAmazon · ONSITE INTERVIEW
- Merge K Sorted Linked ListsThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions