Remove every node that has a node with a strictly greater value somewhere to its right, and return the modified list.
Given the head of a singly linked list, delete every node that has a node with a strictly larger value somewhere later in the list.
Keep only the nodes that are not dominated by a greater value on their right, and return the head of the remaining list.
Example 1
Input
head = [5,2,13,3,8]
Output
[13,8]
Explanation
Node 5 is removed because 13 is greater on its right. Node 2 is removed because 13 is greater on its right. Node 13 stays. Node 3 is removed because 8 is greater on its right. Node 8 stays.
Example 2
Input
head = [1,1,1]
Output
[1,1,1]
Explanation
No node has a strictly greater value to its right, so all nodes remain.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.