Sort Linked List Already Sorted Using Absolute Values
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
You are given the head of a linked list that is sorted in non-decreasing order of the **absolute values** of its nodes. Rearrange the list so that it is sorted in non-decreasing order of the **actual** values, and return the new head.
A general sort costs O(n log n). Solve it in O(n) time with O(1) extra space by exploiting the existing order.
Examples
Constraints
- 1 <= number of nodes <= 10^5
- -5000 <= Node.val <= 5000
- The list is sorted by absolute value in non-decreasing order
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.