Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
We can use a stack that stores nodes in monotone decreasing order of value. When we see a node_j with a larger value, every node_i in the stack has next_larger(node_i) = node_j .