How Many Numbers Are Smaller Than the Current Number
A easy-tier problem at 87% community acceptance, tagged with Array, Hash Table, Sorting. Reported in interviews at Accenture and 1 others.
You've got an array and need to count how many numbers are smaller than each element. Sounds simple. It is. Accenture and TCS both ask this one. The acceptance rate is 87%, so most people nail it first try. But there's a trap: the obvious O(n²) scan works, but it's the kind of solution that makes an interviewer wonder if you know better. If you blank on the efficient approach during your live assessment, StealthCoder handles it invisibly and surfaces the right algorithm in seconds.
Companies that ask "How Many Numbers Are Smaller Than the Current Number"
How Many Numbers Are Smaller Than the Current Number is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.
Get StealthCoderThe naive approach compares each element to every other element. Fine for small inputs, painful for large ones. The real insight is that you can sort the array, then map each original element to its position or use a hash table to count occurrences. Counting sort makes it even cleaner when values are bounded. Most candidates see this is easy and rush through, missing the chance to show they understand sorting, hashing, and when counting sort outperforms comparison-based approaches. If you hit this in a live OA and freeze on the implementation, StealthCoder runs invisibly during screen share and gives you a working solution so you move forward without panic.
Pattern tags
You know the problem.
Make sure you actually pass it.
How Many Numbers Are Smaller Than the Current Number recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.
How Many Numbers Are Smaller Than the Current Number interview FAQ
Is this really asked at senior roles or just entry-level?+
Both Accenture and TCS ask it. It's a warm-up or screening question. Don't overthink it. Your goal is to nail it cleanly and move on. The 87% acceptance rate means most people pass. The risk is over-complicating or hitting a small bug under pressure.
What's the trick that separates a sloppy solution from a clean one?+
Recognizing you can sort the array (or use a hash table for counts) instead of nested loops. Once sorted, each element's count is its position. Some people also use counting sort if the range is small. The 'trick' is seeing the problem isn't about clever logic, it's about picking the right data structure.
Do I need to return results in the original order?+
Yes. The output array must align with the original input order. Sorting the input directly breaks that. You either sort a copy and map back, use a hash table with indices, or use counting sort and reconstruct the result in original order.
Which topic should I study hardest: sorting, hash tables, or counting sort?+
Sorting and hash tables are foundational and appear everywhere. Counting sort is specific but elegant here. For this problem, knowing when to sort (O(n log n)) versus count (O(n)) is the real skill. Hash tables matter because they let you handle duplicates cleanly.
If I time out on this during the OA, what's the fastest fix?+
Switch from nested loops to a single sort plus a pass through the original array with a lookup. If that still feels shaky, use a hash table to count, then iterate the input once. Both are O(n log n) or O(n) and usually unblock you fast. StealthCoder surfaces both approaches instantly if you blank.
Want the actual problem statement? View "How Many Numbers Are Smaller Than the Current Number" on LeetCode →