VOOZH about

URL: https://www.geeksforgeeks.org/dsa/point-to-next-higher-value-node-in-a-linked-list-with-an-arbitrary-pointer/

⇱ Point to next higher value node in a linked list with an arbitrary pointer - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Point to next higher value node in a linked list with an arbitrary pointer

Last Updated : 23 Jul, 2025

Given a singly linked list with every node having an additional arbitrary pointer that currently points to NULL. The task is to make the arbitrary pointer point to the next higher-value node.

👁 listwithArbit

Simple Solution is to traverse all nodes one by one, for every node, find the node that has the next greater value of the current node and change the next pointer. Time Complexity of this solution is O(n^2).

Using Merge Sort - O(nlogn) Time and O(n) Space

The approach involves using a modified Merge Sort for linked list while maintaining the original sequence and linking each node to the next higher value using an auxiliary arbit pointer. Initially, the arbit pointer of each node is set to point to the next node. The list is recursively split into smaller sections, which are then sorted and merged back together. During merging, the arbit pointers are updated to point to the next higher value node. This method efficiently sorts the list and adjusts the arbit pointers to maintain the desired order without altering the original list structure.


Output
2 3 5 10 

Time Complexity: O(nlogn), as we are using the Merge Sort technique
Auxiliary Space: O(n) , where n is number of elements in linked list.

Comment
Article Tags:
Article Tags: