X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Absolute List Sorting
Easy Accuracy: 51.61% Submissions: 18488 Points: 2

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 ≤  ≤ 104

-105 ≤ L[i] ≤ 105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Absolute List Sorting

Output Window