We’re preparing your current view and syncing the latest data.
You are given an integer array nums and an integer k. A subarray is called centered if the subarray includes the index k and the minimum element of the subarray is equal to the subarray's starting element and the maximum element of the subarray is equal to the subarray's ending element (or vice versa). Your task is to determine the number of such centered subarrays within the given array.
Example 1
Input
nums = [1,3,2,4,5], k = 2
Output
3
Explanation
The centered subarrays at index 2 are [2], [3,2], and [2,4]. These satisfy the conditions that the minimum element is at one end and the maximum at the other, includes index 2.