Back to problems

Check Alternating Peaks and Valleys in a Circular Array

Algorithm · Capital One · Easy

You are given an integer sequence nums of length n. Consider the array to be circular: the element after nums[n-1] is nums[0], and the element before nums[0] is nums[n-1]. An array is said to follow an alternating peak–valley pattern if every element is either strictly greater than both of its two circular neighbors (a peak) or strictly smaller than both circular neighbors (a valley). In other words, for each index i, either nums[i] is a local maximum in the circular sense,…

Checking your access…