Close
Topic list
MEDIUM
20 mins
Sorting
Topics (Covered in this problem)
Problem solved
Skill meter
-
-
Sorting
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Contributed by
Prateek_18cb
Medium
0/80
Avg time to solve 20 mins
Success Rate 80 %
Share

## Problem Statement

#### You are given a linked list of 'N' nodes where nodes can contain values 0, 1, and 2 only. Your task is to sort the linked list.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
2
0 1 1 2 2 1 1 1 0 1 -1
2 2 2 1 0 -1
##### Sample Output 1 :
0 0 1 1 1 1 1 1 2 2
0 1 2 2 2
##### Explanation of The Sample Input 1 :
For the first test case :
The given linked list is :
0 -> 1 ->  1 ->  2 -> 2 -> 1 -> 1 -> 1 -> 0 -> 1 -> null

Therefore after sorting the list will become :
0 -> 0 ->  1 ->  1 -> 1 -> 1 -> 1 -> 1 -> 2 -> 2 -> null

For the second test case :
The given linked list is :
2 -> 2 ->  2 ->  1 -> 0 -> null

Therefore after sorting the list will become-
0 -> 1 ->  2 ->  2 -> 2 -> null
3
0 0 0 -1
0 1 1 2 2 -1
2 2 2 2 2 0 -1
0 0 0
0 1 1 2 2
0 2 2 2 2 2
Auto
Console