Sort a Linked List of 0s, 1s and 2s

Medium Problems of Singly Linked List DSA practice problem on Onlearn.

Difficulty: medium.

Topics: How can you sort a linked list containing only 0's, 1's, and 2's by rearranging its links (not by swapping data)?, Linked List, Node, Pointer, Singly Linked List, Sorting, Time Complexity, Space Complexity, Big O Notation, Algorithm, counting sort, linked list manipulation, sorting algorithms, two pointer technique, Linked List Operations, Linked List Sorting.

Given a singly linked list containing N nodes, where each node's data is either 0, 1, or 2, sort the linked list by changing its links. You are not allowed to change the data of the nodes. Input: The head of the singly linked list. Output: The head of the sorted singly linked list. Constraints: 1 <= N <= 10^5 Node.data is 0, 1, or 2. Example 1: Input: 1 0 2 1 0 NULL Output: 0 0 1 1 2 NULL Difficulty: Medium