Sort a Linked List in Descending Order
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks most first attempts at this Microsoft OA, reported in September 2025, is reaching for an array copy and bubble sort on a list that can hit 50000 nodes. That's O(n^2) and it times out. The task is simple on paper: sort a singly linked list in nonincreasing order, keep duplicates, handle an empty list. The pattern is linked-list merge sort. If you blank mid-assessment, StealthCoder runs invisibly as a safety net and reads the problem for you. Better to walk in knowing the plan.
The problem
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) → ListNode Examples Example 1 head = [4,2,1,3] return = [4,3,2,1] 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] 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 50000 nodes. Every node value is a signed 32-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is merge sort on the list itself. Find the middle with slow and fast pointers, cut the list in two, recursively sort each half, then merge. The only twist is the merge comparison: take the larger value first, so you get descending order. Use a dummy head node to keep the merge clean. The common pitfall is forgetting to sever the link at the middle, which leaves the first half still pointing into the second and creates infinite recursion or a cycle. Another one is the base case: return head when it's null or has a single node, which covers the empty list example. Don't use recursion-free tricks unless you're sure. Depth is only log n, so recursion is safe at 50000 nodes. Values are signed 32-bit, so compare directly and don't subtract. If you freeze on pointer surgery during the live OA, StealthCoder is the hedge that gives you the full solution.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Sort a Linked List in Descending Order cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as sort list. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Microsoft's OA.
Microsoft reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sort a Linked List in Descending Order FAQ
How hard is the Microsoft descending linked list sort really?+
It's medium. The idea is easy, the pointer handling is where people slip. You need middle-finding, splitting, and merging, all on a singly linked list. If you've written merge sort on a list once, this is a small tweak. If not, expect to fumble the split.
What's the trick to sorting a linked list fast?+
Merge sort. Split at the middle using slow and fast pointers, sort both halves, merge by taking the larger head first. That gives O(n log n) time and no random access needed, which linked lists don't have anyway.
Can I just copy values into an array and sort?+
Often yes for correctness, and it's O(n log n) with a built-in sort. Then write values back in descending order. But the assessment may expect node relinking, so know the merge sort approach. The array route is a fallback if you run low on time.
What edge cases should I test?+
Test the empty list, a single node, duplicates, all negative values, and an already ascending list. Also check that you cut the list at the middle. Missing that cut is the most common bug and it shows up on even two-node lists.
How do I prepare for this in 48 hours?+
Write list merge sort from scratch twice, once ascending and once descending. Practice the slow and fast pointer split until it's automatic. Then write a dummy-head merge function. That's the whole problem, and it takes under an hour of focused repetition.