
Asked in Josh Technology Group
Sort Linked List Based on Actual Values
You are given a Singly Linked List of integers that is initially sorted according to the absolute values of its elements. Your task is to sort this Linked List based on the actual integer values.
The absolute value of a number x
, denoted as |x|
, is the non-negative value of x
without regard to its sign.
Input:
The first line consists of a single integer ‘T’, denoting the number of test cases. Each test case includes a single line containing the elements of the singly linked list, separated by spaces, and terminated by -1. The value -1 is not part of the list data and serves as a terminator.
Output:
For each test case, provide the sorted linked list where the elements are separated by a space, ending with -1.
Example:
Input:
1 -> -2 -> 3 -1
Output:
-2 -> 1 -> 3 -1
Constraints:
- 1 <= T <= 10
- 1 <= N <= 5 * 104
- -109 <= data <= 109 (data ≠ -1)
- The input list is guaranteed to be sorted based on absolute values.
Note:
The function should be implemented to sort the linked list. Output handling has been dealt with separately.

AnswerBot
1y
The task is to sort a singly linked list based on actual values instead of absolute values.
Traverse the linked list and store the values in an array
Sort the array using any sorting algorithm
Create a n...read more
Help your peers!
Add answer anonymously...
Top Front end Developer Interview Questions Asked at Josh Technology Group
Q. Implement a live coding round to build a small CRUD-based application.
Q. Non-Decreasing Array Problem Statement Given an integer array ARR of size N, det...read more
Q. Diameter of a Binary Tree Problem Statement Given a binary tree, return the leng...read more
Interview Questions Asked to Front end Developer at Other Companies
Top Skill-Based Questions for Josh Technology Group Front end Developer
Web Development Interview Questions and Answers
250 Questions
JavaScript Interview Questions and Answers
250 Questions
CSS Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
HTML Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

