FastPrepCircular High-Low Pattern

Circular High-Low Pattern

Capital One logoCapital One● EasyFULLTIMEOA
Learn

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[]) → boolean

Examples

Example 1

values = [1,3,2,4]return = true

Reading around the circle gives low, high, low, high.

Example 2

values = [1,2,3,4]return = false

Values 2 and 3 are neither alternating circular extrema.

Constraints

  • 4 <= values.length <= 100000.
  • values.length is even.
  • -1000000000 <= values[i] <= 1000000000.

More Capital One problems

See Capital One hiring insights
public boolean isCircularHighLow(int[] values) {
    // Write your code here.
}
values[1,3,2,4]
expectedtrue
Checking account…