Find All Good Indices
You are given a 0-indexed integer array nums of size n and a positive integer k.
We call an index i in the range k <= i < n - k good if the following conditions are satisfied:
- The
kelements that are just before the indexiare in non-increasing order. - The
kelements that are just after the indexiare in non-decreasing order.
Return an array of all good indices sorted in increasing order.
Example 1
Input
nums = [2,1,1,1,3,4,1], k = 2Output
[2,3]There are two good indices: index 2 because [2,1] is non-increasing and [1,3] is non-decreasing, and index 3 because [1,1] is non-increasing and [3,4] is non-decreasing.
Example 2
Input
nums = [2,1,1,2], k = 2Output
[]There are no good indices in this array.
Constraints
- n == nums.length
- 3 <= n <= 10^5
- 1 <= nums[i] <= 10^6
- 1 <= k <= n / 2