DAYS
HOUR
MINS
SEC
Error
Given a linked list L of N nodes, sorted in ascending order based on the absolute values of its data,i.e. negative values are considered as positive ones. Sort the linked list according to the actual values, consider negative numbers as negative and positive number as positive.
Example 1:
Input:
List: 1, -2, -3, 4, -5
Output:
List: -5, -3, -2, 1, 4
Example 2:
Input:
List: 5, -10
Output:
List: -10, 5
Your Task:
You don't need to read or print anyhting. Your Task is to comple the function sortList() which takes the head of the Linked List as input parameter and sort the list in ascending order. Don't create a new Linked List instead rearrange the given List.
Expected Time Complexity: O(N)
Expected Space Complexity: O(1)
Constraints
1 ≤ N ≤ 104
-105 ≤ L[i] ≤ 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes