Medium · Database
Managers With Two Reports
Given Employee(id, name, managerId), return Manager and ReportCount for managers with at least two direct reports. A managerId of 0 means no manager. Count only direct reports, not the entire reporting tree; row order does not matter.
Examples
Example 1
{
"employees": [
{"id": 1, "name": "Ada", "managerId": 0},
{"id": 2, "name": "Ben", "managerId": 1},
{"id": 3, "name": "Cy", "managerId": 1},
{"id": 4, "name": "Dee", "managerId": 2}
]
}Output: [{"Manager":"Ada","ReportCount":2}]
Example 2
{
"employees": [
{"id": 10, "name": "Eve", "managerId": 0},
{"id": 11, "name": "Fox", "managerId": 10},
{"id": 12, "name": "Gia", "managerId": 11}
]
}Output: []
Rebuild it in the studio
20 free core interview problems with full runner & lessons; explore the complete 380+ library with Pro.