First traverse a linked list into an array. Thereafter construct a monotonically decreasing stack from right to left. If the topmost value of each element is greater than the current value, update the topmost value to the next greater value than the current value and also push it on the stack. Otherwise, open the stack until the topmost value is greater than the current value or the stack is empty. For an empty stack, there is no next max value for the current value, simply set 0 as the next max value as needed for your problem.