Point to Next Increasing Node

Difficulty: EASY
Avg. time to solve
10 min
Success Rate

Problem Statement
Suggest Edit

Given singly linked list with every node having an additional “arbitrary” pointer. This arbitrary pointer is currently pointing to NULL. You need to make this arbitrary pointer of each node point to the next higher value node in the input list.

You just need to return the head of new linked list, don't print the elements.

Input format :
Line 1 : Linked list elements of length n (separated by space and terminated by -1)
Output format :
Updated list elements (separated by space)
Constraints :
1 <= N <= 10^4
Sample Input :
 12 5 2 8 -1

Note :

-1 at the end of input is just a terminator representing the end of linked list. This -1 is not part of the linked list. Size of given linked list is 4.
Sample Output :
 2 5 8 12 
Want to solve this problem? Login now to get access to solve the problems