In the Count the Number of K-Big Indices coding problem, an index i is considered "-big" if there are at least elements to its left that are strictly smaller than nums[i], AND at least elements to its right that are also strictly smaller than nums[i].
Your task is to return the total count of such indices in the array.
Amazon uses this "Hard" problem to test proficiency with order-statistic data structures. It evaluates whether a candidate can efficiently perform "count smaller than " queries over a dynamic range. A naive solution () will not pass. The problem requires a strategy that runs in or , demonstrating mastery of Binary Indexed Trees (BIT) or Priority Queues.
This problem can be solved using two passes with Binary Indexed Trees or Heaps.
nums[i]. If the count is , mark left_valid[i] = true. Then add nums[i] to the BIT.
nums[i] > heap.top(), then at least elements are smaller.right_valid[i].left_valid and right_valid are true.nums = [2, 3, 6, 5, 2, 3], k = 2
nums[i] instead of strictly .Practice the "Two Pass" pattern. Many array problems that require checking conditions on both the left and right side of an element can be solved by running the same logic twice (once forward, once backward) and intersecting the results.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Number of Pairs Satisfying Inequality | Hard | Solve | |
| Count of Range Sum | Hard | Solve | |
| Count of Smaller Numbers After Self | Hard | Solve | |
| Reverse Pairs | Hard | Solve | |
| Count Good Triplets in an Array | Hard | Solve |