Time for News to Reach an Entire Management Tree

Quick Overview

Time for News to Reach an Entire Management Tree. The n employees form a tree rooted at headID, whose manager is-1.

Time for News to Reach an Entire Management Tree

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem The n employees form a tree rooted at headID, whose manager is -1. Once employee i receives the news, all direct subordinates receive it informTime[i] minutes later and can then spread it in parallel. The head knows at time 0. Return when every employee has received the news. ```cpp class Solution { public: int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime); }; ``` ### Examples **Example 1:** ```text Input: n = 3, headID = 0, manager = [-1,0,1], informTime = [2,3,0] Output: 5 Explanation: Employee1 learns at2 and employee2 learns at2+3=5. ``` **Example 2:** ```text Input: n = 3, headID = 1, manager = [1,-1,1], informTime = [0,4,0] Output: 4 Explanation: Both direct subordinates receive the news together four minutes after the head. ``` ### Constraints - `1 <= n <= 100000` and `0 <= headID < n`. - Both arrays have length n; the hierarchy is a tree and all employees can be informed. - `manager[headID] == -1`. For every non-head employee `i`, `0 <= manager[i] < n`. - Every informTime is in `[0,1000]`, and is 0 for a leaf. ### Practice Assumptions The source lists a universal nonnegative manager bound alongside `manager[headID] == -1`. This practice problem treats the head as the stated exception: only non-head managers must lie in `[0,n-1]`. ```hint Read the boundary condition Distinguish reception time from a subordinate's later forwarding delay. Include parallel branches and the head-only hierarchy. ```

Overview: Time for News to Reach an Entire Management Tree. The n employees form a tree rooted at headID, whose manager is-1.

Microsoft logo
Microsoft
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

The n employees form a tree rooted at headID, whose manager is -1. Once employee i receives the news, all direct subordinates receive it informTime[i] minutes later and can then spread it in parallel. The head knows at time 0. Return when every employee has received the news.

class Solution {
public:
    int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime);
};

Examples

Example 1:

Input: n = 3, headID = 0, manager = [-1,0,1], informTime = [2,3,0]
Output: 5
Explanation: Employee1 learns at2 and employee2 learns at2+3=5.

Example 2:

Input: n = 3, headID = 1, manager = [1,-1,1], informTime = [0,4,0]
Output: 4
Explanation: Both direct subordinates receive the news together four minutes after the head.

Constraints

  • 1 <= n <= 100000 and 0 <= headID < n .
  • Both arrays have length n; the hierarchy is a tree and all employees can be informed.
  • manager[headID] == -1 . For every non-head employee i , 0 <= manager[i] < n .
  • Every informTime is in [0,1000] , and is 0 for a leaf.

Practice Assumptions

The source lists a universal nonnegative manager bound alongside manager[headID] == -1. This practice problem treats the head as the stated exception: only non-head managers must lie in [0,n-1].