Leetcode Problem 2519. Count the Number of K-Big Indices

2519. Count the Number of K-Big Indices

Leetcode Solutions

Two Priority Queues Approach

  1. Initialize a max-heap left to keep track of the k smallest elements seen so far from the left.
  2. Initialize an array left_good to mark indices that have at least k smaller elements to the left.
  3. Iterate over the array from index k to n-k, updating the left heap and left_good array.
  4. Initialize a max-heap right to keep track of the k smallest elements seen so far from the right.
  5. Initialize a counter bigIndices to count the k-big indices.
  6. Iterate over the array from index n-k-1 to k, updating the right heap and incrementing bigIndices if both left and right conditions are met.
  7. Return the count bigIndices.
UML Thumbnail

Binary Indexed Tree (Fenwick Tree) Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...