Sort List
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given the head of a singly linked list, return the list sorted in **ascending** order by value. Nodes with equal values may appear in any order relative to each other, since they are indistinguishable in the output.
Arrays are not allowed to do the heavy lifting here: aim for O(n log n) time. As a follow-up, try to use only O(1) extra space with a bottom-up merge sort.
An empty list sorts to an empty list.
Examples
Constraints
- 0 <= number of nodes <= 5 * 10^4
- -10^5 <= Node.val <= 10^5
- Values may repeat
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.