A singly linked list is a type of linked list that is unidirectional; that is, it can be traversed in only one direction from head to the last node (tail).
If the given linked list is already a smart linked list, you don’t have to do anything.
The first line of input contains an integer T, the number of test cases.
The first and the only line of every test case contains the elements of the singly linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
For every test case, return the modified linked list. The elements of the modified list should be single-space separated, terminated by -1.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5 * 10^4
-10^3 <= data <= 10^3 and data != -1
Time Limit: 1 sec
The idea is very simple. We will consider every node and check all the nodes to its right side. If we encounter a node with greater value in the right side of the current node, we will simply remove the current node.
Algorithm:
The idea is to keep track of the max valued node as we go through the linked list recursively.
We will create a recursive function 'SMART_LIST_HELPER' that takes two arguments, the head of the linked list and a pointer to an integer 'MAX_VALUE'. Initially, 'MAX_VALUE' is pointing to -1000 as it is the minimum value a node can acquire.
Algorithm for the 'SMART_LIST_HELPER':
The final returned linked list will be a smart linked list.
Algorithm:
Mario And His Princess
LRU Cache
8-Queen Problem
Delete Nodes On Regular Intervals
Add One To Linked List