Skip to main content
LeetCode 690, Medium. Topics: Array, Hash Table, Tree, Depth-First Search, Breadth-First Search. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

You have a data structure of employee information, including the employee’s unique ID, importance value, and direct subordinates’ IDs. You are given an array of employees employees where:
  • employees[i].id is the ID of the i^th employee.
  • employees[i].importance is the importance value of the i^th employee.
  • employees[i].subordinates is a list of the IDs of the direct subordinates of the i^th employee.
Given an integer id that represents an employee’s ID, return the total importance value of this employee and all their direct and indirect subordinates.

Examples

Example 1
Example 2

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.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026