Spring Hire Sale
Limited Time Deal: Unlock all premium questions for over 30% off
$10.42$7.08
08
:
06
:
42
:
47
Back to Dashboard
Peak Value Processing Order
Medium
You are given a list of unique integers values. At each step, identify all eligible values: a value is eligible if it is strictly greater than all of its current neighbors (values immediately to its left and right in the remaining list). An element at the left end only needs to be greater than its right neighbor; an element at the right end only needs to be greater than its left neighbor; a single remaining element is always eligible.
Each step, remove the smallest eligible value from the list and append it to the result. Repeat until all values have been removed. Return the order in which they were removed. ...