The "Count of Smaller Numbers After Self interview question" is a classic hard-level challenge. You are given an integer array, and for each element, you need to count how many elements to its right are strictly smaller than it. The output is an array of these counts. For instance, in the array [5, 2, 6, 1], there are two numbers smaller than 5 to its right (2 and 1), and zero numbers smaller than 1 to its right.
Tech giants like Microsoft, Meta, and TikTok use the "Count of Smaller Numbers After Self coding problem" to test a candidate's ability to work with dynamic statistics. It requires more than a simple sort; it requires a structure that can update and query counts simultaneously as you move through the array. It evaluates knowledge of "Segment Tree interview pattern" or "Binary Indexed Tree (BIT)" and the ability to adapt Merge Sort for counting.
This problem is typically solved using one of three patterns:
Input: [5, 2, 6, 1]
1. Count of smaller numbers seen so far: 0. Result: [?, ?, ?, 0].6: Smallest numbers seen so far is 1. Count smaller than 6 is 1. Result: [?, ?, 1, 0].2: Smallest number seen so far is 1. Count smaller than 2 is 1. Result: [?, 1, 1, 0].5: Numbers seen are 1, 6, 2. Smaller than 5 are 1 and 2. Count is 2. Result: [2, 1, 1, 0].Practice "Coordinate Compression." It is a vital companion technique for "Binary Indexed Tree interview pattern" problems. It allows you to map large or negative values into a smaller range of positive integers, making BIT or Segment Tree solutions much more robust.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Reverse Pairs | Hard | Solve | |
| Number of Pairs Satisfying Inequality | Hard | Solve | |
| Count of Range Sum | Hard | Solve | |
| Count Good Triplets in an Array | Hard | Solve | |
| Count the Number of K-Big Indices | Hard | Solve |