Circular High-Low Pattern
Problem statement
Given an even-length circular integer array values, return whether its elements strictly alternate between local lows and local highs.
For every index i, compare values[i] with its two circular neighbors. Every element must be strictly greater than both neighbors or strictly less than both neighbors, and adjacent elements must have opposite roles. Equal adjacent values are not allowed.
Function
isCircularHighLow(values: int[]) → booleanExamples
Example 1
values = [1,3,2,4]return = trueReading around the circle gives low, high, low, high.
Example 2
values = [1,2,3,4]return = falseValues 2 and 3 are neither alternating circular extrema.
Constraints
4 <= values.length <= 100000.values.lengthis even.-1000000000 <= values[i] <= 1000000000.