

You need to return the head after populating the ‘arbit’ pointer.
Given ‘head’ as 3 -> 5 -> 2 -> 1.

After populating the arbitrary pointer, each node's ‘arbit’ pointer would point to 5 2 1 -1 respectively.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The second line of each test case contains space-separated integers, denoting the elements in linked list nodes, and -1 denotes the end of the linked list.
For each test case, print integers denoting the value of the nodes being pointed by the arbitrary pointer of that node, if the arbitrary pointer points to NULL, print -1.
You are supposed to return the head of the linked list, whose arbitrary pointer is populated.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 5000
0 <= ‘data’ <= 10 ^ 4 and ‘data’ != -1
Time Limit: 1sec.
The idea is to loop for every node and find the node with the greatest value with respect to the current node.
The steps are as follows:
The idea is to Reverse the given linked list. Start traversing the linked list and store the maximum value node encountered so far. Make the arbitrary pointer of every node to point to the max. If the data in the current node is more than the max node so far, update max. Reverse the modified linked list and return head.
The steps are as follows: