630. Remove Nodes From Linked List

MediumStackMonotonic StackLinked List

Given a linked list represented as an array nums (head first), remove every node that has a node with a strictly greater value anywhere to its right. Return the values of the remaining nodes in order. The input is JSON {nums}.

Input: JSON {nums}.

Output: Array — the remaining node values.

Examples

Example 1
Input: {"nums":[5,2,13,3,8]}
Output: [13,8]
Explanation: 5 and 2 have 13 to the right; 3 has 8.
Example 2
Input: {"nums":[1,1,1,1]}
Output: [1,1,1,1]
Explanation: None have a greater to the right.
Example 3
Input: {"nums":[9]}
Output: [9]
Explanation: Single node.

Constraints

Asked by

AmazonMicrosoftGoogleMeta
Solve this problem in the editor →