- Difficulty: Hard
- Tags: LeetCode, Hard, Binary Indexed Tree, Segment Tree, Array, Binary Search, Divide and Conquer, Ordered Set, Merge Sort, leetcode-2519, Binary Heap, O(nlogk), O(n), 🔒, Heap, Sorted List
Problem
You are given a 0-indexed integer array nums
and a positive integer k
.
We call an index i
k-big if the following conditions are satisfied:
- There exist at least
k
different indicesidx1
such thatidx1 < i
andnums[idx1] < nums[i]
. - There exist at least
k
different indicesidx2
such thatidx2 > i
andnums[idx2] < nums[i]
.
Return the number of k-big indices.
Â
Example 1:
Input: nums = [2,3,6,5,2,3], k = 2 Output: 2 Explanation: There are only two 2-big indices in nums: - i = 2 --> There are two valid idx1: 0 and 1. There are three valid idx2: 2, 3, and 4. - i = 3 --> There are two valid idx1: 0 and 1. There are two valid idx2: 3 and 4.
Example 2:
Input: nums = [1,1,1], k = 3 Output: 0 Explanation: There are no 3-big indices in nums.
Â
Constraints:
1 <= nums.length <= 105
1 <= nums[i], k <= nums.length