Problem of the day
The first line of the input contains 'L' space-separated integers denoting the elements of the singly linked list terminated by -1.
Hence, -1 would never be a list element.
Print the modified linked list. The elements of the modified list should be single-space separated, terminated by -1.
You don’t need to print anything; It has already been taken care of. Just implement the given function.
0 <= L <= 5 * 10^5
-10^9 <= node.data <= 10^9 and data != -1
Where 'L' is the number of nodes in the Linked-List.
Time Limit : 1 sec
10 14 6 80 55 56 77 -1
10 14 80 56 77 -1
For the given linked list, nodes with the values 6 and 55 have a greater valued node to their left (14 and 80 respectively).
Thus, we remove these 2 nodes from the linked list and get the modified list as shown in the output.
Note that the node with the value 56 should not be deleted as its left adjacent node has the value 55 which is not greater than 56.
80 70 60 50 -1
80 -1
For the given linked list, nodes with the values 70, 60, and 50 have a greater valued node to their left (80, 70, and 60 respectively).
Thus, we remove these 3 nodes from the linked list and get the modified list as shown in the output.