1731. The Number of Employees Which Report to Each Employee LeetCode Solution
In this guide, you will get 1731. The Number of Employees Which Report to Each Employee LeetCode Solution with the best time and space complexity. The solution to The Number of Employees Which Report to Each Employee problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- The Number of Employees Which Report to Each Employee solution in C++
- The Number of Employees Which Report to Each Employee solution in Java
- The Number of Employees Which Report to Each Employee solution in Python
- Additional Resources

Problem Statement of The Number of Employees Which Report to Each Employee
Table: Employees
+————-+———-+
| Column Name | Type |
+————-+———-+
| employee_id | int |
| name | varchar |
| reports_to | int |
| age | int |
+————-+———-+
employee_id is the column with unique values for this table.
This table contains information about the employees and the id of the manager they report to. Some employees do not report to anyone (reports_to is null).
For this problem, we will consider a manager an employee who has at least 1 other employee reporting to them.
Write a solution to report the ids and the names of all managers, the number of employees who report directly to them, and the average age of the reports rounded to the nearest integer.
Return the result table ordered by employee_id.
The result format is in the following example.
Example not found
Constraints not found
Complexity Analysis
- Time Complexity: Google AdSense
- Space Complexity: Google Analytics
1731. The Number of Employees Which Report to Each Employee LeetCode Solution in C++
SELECT
Manager.employee_id,
Manager.name,
COUNT(Employee.employee_id) AS reports_count,
ROUND(AVG(Employee.age)) AS average_age
FROM Employees AS Manager
INNER JOIN Employees AS Employee
ON (Employee.reports_to = Manager.employee_id)
GROUP BY 1
ORDER BY 1;
/* code provided by PROGIEZ */
1731. The Number of Employees Which Report to Each Employee LeetCode Solution in Java
N/A
// code provided by PROGIEZ
1731. The Number of Employees Which Report to Each Employee LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.