Sum Importance over an Employee's Reachable Subordinates
Quick Overview
Sum Importance over an Employee's Reachable Subordinates. Each Employee object has a unique id, an integer importance, and a list subordinates of direct report IDs.
Sum Importance over an Employee's Reachable Subordinates
Company: Bloomberg
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
Each Employee object has a unique id, an integer importance, and a list subordinates of direct report IDs. Given the objects and an employee id, return the sum of that employee's importance and every directly or indirectly subordinate employee's importance, counting each employee once. Preserve vector<Employee*> employees and int id; displayed triples are only notation for the objects.
```cpp
class Solution {
public:
int getImportance(vector<Employee*> employees, int id);
};
```
### Examples
**Example 1:**
```text
employees = [[1,4,[2]],[2,-1,[3]],[3,6,[]]], id = 1
Output: 9
Explanation: 4-1+6 includes all three reachable employees.
```
**Example 2:**
```text
employees = [[7,8,[9]],[9,2,[]]], id = 9
Output: 2
Explanation: A subordinate query does not include its leader.
```
### Constraints
- There are 1..2000 Employee objects with distinct IDs in 1..2000. Importance values are in -100..100. Each employee has at most one direct leader and may have several reports. Every listed subordinate ID names a supplied employee.
### Clarifying Questions
Follow subordinate IDs rather than array positions and preserve object fields and negative importance values.
```hint Read the boundary condition
How can the traversal find an employee object efficiently from a subordinate ID?
```
### Contract considerations
Follow subordinate IDs rather than array positions and preserve object fields and negative importance values.
Overview: Sum Importance over an Employee's Reachable Subordinates. Each Employee object has a unique id, an integer importance, and a list subordinates of direct report IDs.
Sum Importance over an Employee's Reachable Subordinates
Bloomberg
Jul 2, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
Each Employee object has a unique id, an integer importance, and a list subordinates of direct report IDs. Given the objects and an employee id, return the sum of that employee's importance and every directly or indirectly subordinate employee's importance, counting each employee once. Preserve vector<Employee*> employees and int id; displayed triples are only notation for the objects.
class Solution {
public:
int getImportance(vector<Employee*> employees, int id);
};
Examples
Example 1:
employees = [[1,4,[2]],[2,-1,[3]],[3,6,[]]], id = 1
Output: 9
Explanation: 4-1+6 includes all three reachable employees.
Example 2:
employees = [[7,8,[9]],[9,2,[]]], id = 9
Output: 2
Explanation: A subordinate query does not include its leader.
Constraints
There are 1..2000 Employee objects with distinct IDs in 1..2000. Importance values are in -100..100. Each employee has at most one direct leader and may have several reports. Every listed subordinate ID names a supplied employee.
Clarifying Questions Guidance
Follow subordinate IDs rather than array positions and preserve object fields and negative importance values.
Contract considerations
Follow subordinate IDs rather than array positions and preserve object fields and negative importance values.