Skip to content

Practice Employee Importance

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#690
LeetCode Problem

Employee Importance

Problem Statement

Each employee record stores id, importance and subordinates, where subordinates lists the IDs of that employee's direct reports. Given the records and a target id, return the sum of importance for the target employee and every employee reachable through one or more reporting relationships beneath them.

Source: Employee Importance on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
employees = [[1,5,[2,3]],[2,3,[]],[3,3,[]]], id = 1
Output
11

# Example 2

Input
employees = [[1,2,[5]],[5,-3,[]]], id = 5
Output
-3

Constraints

1 <= employees.length <= 2000
1 <= employees[i].id <= 2000
All employees[i].id are unique.
-100 <= employees[i].importance <= 100
One employee has at most one direct leader and may have several subordinates.
The IDs in employees[i].subordinates are valid IDs.

Related LeetCode Problems

Practice more problems similar to Employee Importance.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.