FunctionRacerProblemsRace

Next Greater Node

MediumStacks and queuesPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems