
The first line of input contains an integer ‘T’, the number of test cases.
The first line of each test case contains the linked list separated by space and terminated by -1.
For each test case, print the updated linked list.
Output for each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 3*10^3
Where ‘N’ is the number of nodes in the linked list.
Time Limit : 1 sec
The basic idea is to traverse the linked list recursively. While traversing, we check the adjacent nodes and remove the nodes if they are equal. Else, we traverse further in the linked list.
Here is the algorithm :
The idea is similar to the previous approach. In this approach, we traverse the linked list iteratively and check for adjacent nodes. We also create a new node and attach it to the starting of the linked list, whose next will be pointing to the ‘HEAD’ node to handle the case when the ‘HEAD’ node itself consists of repeating numbers.
Here is the algorithm :
Sorted Doubly Linked List to Balanced BST
Longest Substring with K-Repeating Characters
Expression Add Operators
Gray Code Transformation
Count of Subsequences with Given Sum