The Number of Employees Which Report to Each Employee
A easy-tier problem at 52% community acceptance, tagged with Database. Reported in interviews at ZS Associates and 0 others.
This is a database problem that looks straightforward but trips up candidates who write inefficient joins or forget about the recursive structure hiding in the data. ZS Associates asks it. The setup is simple: you have an employees table with IDs and manager IDs, and you need to count how many people report directly or indirectly to each employee. The 52% acceptance rate tells you most people solve it, but some get the join logic wrong or miss the hierarchical aspect entirely. If you hit this on your assessment and blank on the recursive pattern, StealthCoder surfaces a working solution in seconds while the proctor sees nothing.
Companies that ask "The Number of Employees Which Report to Each Employee"
The Number of Employees Which Report to Each Employee 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 used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe trap is thinking this is just a self-join. You need to count reports at all levels (direct and indirect), not just direct reports. A naive GROUP BY with a single join only catches one level of the hierarchy. The real solution uses either a recursive CTE (in SQL dialects that support it) or a self-join repeated to traverse the tree, or a subquery that walks the chain from each employee up to their manager and counts everyone below them. Most candidates write a join that works for direct reports only, then wonder why their count is too low. Once you recognize it's a tree traversal problem disguised as a SQL query, the pattern becomes clear: for each employee, find everyone in their subtree. StealthCoder detects this pattern instantly and delivers the recursive or multi-level join approach your OA expects.
Pattern tags
You know the problem.
Make sure you actually pass it.
The Number of Employees Which Report to Each Employee 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 used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
The Number of Employees Which Report to Each Employee interview FAQ
Is this really just a self-join problem?+
No. A single self-join only catches direct reports. You need to count the entire subtree under each employee, including indirect reports. That's why recursion or multiple joins are necessary. The acceptance rate reflects how many candidates initially get it wrong with one join and have to rethink the approach.
What SQL technique do I actually need?+
Either a recursive CTE (WITH RECURSIVE in PostgreSQL, MySQL 8+, SQL Server) or repeated self-joins. Some solutions use a subquery that counts all employees whose manager chain includes the target employee. Pick whichever your target database supports best.
Will this appear in other OAs if I see it at ZS?+
Database problems like this are less portable across companies than algorithmic problems, but hierarchy and tree traversal concepts show up everywhere. Learning the recursive CTE pattern here pays off on other data engineering and SQL interview rounds.
What's the most common mistake?+
Writing a single join and grouping by manager ID, which gives you direct reports only. Candidates then submit, fail test cases with indirect reports, and realize the structure is deeper. The second mistake is forgetting to handle NULL manager IDs (the root employee).
How long should this take in a live OA?+
If you know the recursive CTE pattern, 5 to 10 minutes. If you don't, you'll debug the single-join approach for 15 to 20 minutes before recognizing the tree traversal requirement. That's where StealthCoder's instant pattern recognition saves you from burning time on the wrong path.
Want the actual problem statement? View "The Number of Employees Which Report to Each Employee" on LeetCode →