head, the head of a singly linked list of positive numbers.
For each node, find the value of the first node after it whose value is strictly larger. If there is no such node, its answer is 0.
Return the answers as an array: element i belongs to node i of the list (0-based).head=list_node([3, 8, 6, 2, 7]) → [8, 0, 7, 7, 0]
For 3 the first larger value further down is 8. Nothing beats 8, so it gets 0. Both 6 and 2 get 7. The last node gets 0.
head=list_node([5, 5, 5]) → [0, 0, 0]
Equal values do not count as larger, so every answer is 0.
head=list_node([1, 4, 9]) → [4, 9, 0]
head=list_node([3, 8, 6, 2, 7])
[8, 0, 7, 7, 0]
Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.