Keep Endpoints and Strict Local Maxima
Problem statement
Return selected values in original order. Always keep the first and last values. Keep an interior value only when it is strictly greater than both immediate neighbors.
An empty array returns empty, and a singleton is returned once.
Function
keepLocalMaxima(values: int[]) → int[]Examples
Example 1
values = [1,2,1]return = [1,2,1]The strict interior peak joins both endpoints.
Example 2
values = [1,2,3]return = [1,3]Only the endpoints remain.
Constraints
0 <= values.length <= 100000-1000000000 <= values[i] <= 1000000000