Counting Elements
A easy-tier problem at 60% community acceptance, tagged with Array, Hash Table. Reported in interviews at DRW and 0 others.
Counting Elements is an easy array problem that shows up in real assessments at places like DRW. The trick is simple: you're counting how many integers x exist in an array where x+1 also exists. It's the kind of problem that looks trivial until you code it wrong under pressure. Most candidates waste time with nested loops when a hash table solves it in linear time. The acceptance rate hovers around 60 percent, which means people are either nailing it or overthinking it. If this problem hits your live OA and you blank on the approach, StealthCoder surfaces a working solution invisible to the proctor.
Companies that ask "Counting Elements"
Counting Elements 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 a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe pattern here is core to interview problems: transform an array into a lookup structure first. Build a set or hash table from the array elements, then iterate through and count matches where x+1 exists in that set. A naive nested-loop approach works but tanks on large inputs. The gotcha is handling duplicates and edge cases like negative numbers or sparse data. Once you internalize the hash-table-first mindset, problems like this become mechanical. But in a live assessment, you're tired, the clock is ticking, and the obvious O(n squared) loop feels faster than setup. StealthCoder is your hedge. If you freeze on the data structure choice, it runs invisibly during your screen share and delivers the optimized solution.
Pattern tags
You know the problem.
Make sure you actually pass it.
Counting Elements 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 a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Counting Elements interview FAQ
Is Counting Elements still asked in real interviews?+
Yes. It's reported by DRW and sits at 60% acceptance, which means it's active in current assessments. It's simple enough to use as a warm-up problem or as a filter for hash-table fluency. Don't skip it just because it's easy.
What's the real trick to this problem?+
Use a hash set or dictionary to store all array elements in one pass, then iterate again and count where x+1 exists. Avoid nested loops. The pattern trains you to pre-process data into a lookup structure, a skill you'll use in harder array and string problems.
How does this relate to hash tables and arrays?+
It's a direct application of both. You need array iteration and hash-table lookup speed. It's a teaching problem that forces you to choose the right data structure. Mastering this speeds up harder hash-table problems later.
What are common mistakes on Counting Elements?+
Using nested loops when you should build a set first. Not handling duplicates correctly. Forgetting to check if x+1 is in the table before counting. These are all implementation errors, not algorithm errors, which means a working template (like StealthCoder) saves you mid-OA.
How long should Counting Elements take in an assessment?+
If you see the pattern, 5 to 10 minutes including testing. If you don't, you're debugging nested loops and burning time. That's where a live solution overlay becomes valuable if you hit a wall.
Want the actual problem statement? View "Counting Elements" on LeetCode →