Question bank › Graphs Dfs
Dsa Graphs Dfs Easy

The Total Subordinates

An organization is structured as a perfect tree where each person has one direct manager, except the CEO. Given the reporting structure, count the total size of the team managed by a specific person X (including X themselves and all their direct and indirect subordinates). Input: The first line contains N (total people, labeled 0 to N-1). The next N-1 lines each contain two integers: 'M S', where M is the manager and S is the direct subordinate. The last line contains the ID of the person X. Output: The total number of people in X's hierarchy. Example: Input: 5 0 1 0 2 1 3 1 4 1 Output: 3

Key concepts

graphs_dfstrees

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.