530. Count the Number of K Big Indices
You are provided a positive integer k and an integer array nums that is 0-indexed.
An index is referred to as i k-big if the following criteria are met:
- At least k distinct indices of idx1 exist such that nums[idx1] < nums[i] and idx1 < i.
- At least k distinct indices of idx2 exist such that nums[idx2] < nums[i] and idx2 > i.
Give back how many k-big indices there are.
Example 1:
Input : nums = [1, 2, 3, 6, 5, 2, 4, 1] , k = 3
Output : 2
Explanation :
There are only 2 big indices in nums.
index 3 -> There are three valid idx1 0, 1, 2. There are four valid idx2 4, 5, 6, 7.
index 4 -> There are three valid idx1 0, 1, 2. There are three valid idx2 5, 6, 7.
Example 2:
Input : nums = [1, 2, 3, 4, 5, 6, 7] , k = 3
Output : 0
Explanation :
There are only 0 big indices in nums.
Now Your Turn!
Pick the correct output for the given inputInput : nums = [4, 1, 3, 9, 5, 1, 3], k = 2
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 105
- 1 <= nums[i], k <= nums.length