Next Greater Node In Linked List LeetCode solution in Python
1class Solution:2def nextLargerNodes(self, head: Optional[ListNode]) -> List[int]:3stack = []4ans = []5node = head67i = 08while node is not None:9while stack and stack[-1][0] < node.val:10ans[stack[-1][1]] = node.val11stack.pop()1213stack.append((node.val, i))14ans.append(0)15i += 116node = node.next1718return ans