FastPrepSort a Linked List in Descending Order
Problems/Sort a Linked List in Descending Order

Sort a Linked List in Descending Order

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft intern onsite interview. The report gives the follow-up of sorting a linked list in descending order and reusing the merge routine. It leaves out empty input, repeated values, examples, the function signature and the limits. Our version is about 84% the same as the reported question.

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]
head
4213
→
return
4321
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]
head
-15340
→
return
5430-1
Moved or new

Positive, zero, and negative values are all ordered in descending numeric order.

Example 3

head = []return = []
head
empty
return
empty

An empty list is already sorted.

Constraints

  • The list contains at most 50000 nodes.
  • 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

Interview reports that mention this question

  • Microsoft CoreAI SWE Intern Loops: 4 Experiences (Part 2 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode sortListDescending(ListNode head) {
        // Write your code here.
    }

}
Checking account…