Next Greater Node
For each node, find the first node after it with a strictly larger value. Return a normal Python list with one number per node: that larger value, or 0 if there is none. The list is passed in as head.
Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.
Example 1
head [2,1,5]
returns [5,5,0]
2 -> 5, 1 -> 5, and nothing after 5.
Example 2
head [2,7,4,3,5]
returns [7,0,5,5,0]
7, 0, 5, 5, 0.
Constraints
0 <= number of nodes <= 1001 <= Node.val <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.