FastPrepTime to Inform Every Employee

Time to Inform Every Employee

Amazon logoAmazon● MediumINTERNONSITE INTERVIEW
Learn

Problem statement

An organization contains n employees numbered from 0 through n - 1. The unique head has manager -1. When employee i learns urgent news, that employee needs informTime[i] minutes to inform every direct report simultaneously. Return the number of minutes until every employee has learned the news.

Function

minutesToInformEveryone(n: int, headId: int, manager: int[], informTime: int[]) → int

Examples

Example 1

n = 6headId = 2manager = [2,2,-1,2,2,2]informTime = [0,0,1,0,0,0]return = 1

The head directly informs every other employee in one minute.

Example 2

n = 4headId = 0manager = [-1,0,0,1]informTime = [2,3,0,0]return = 5

The deepest recipient is reached after the head and employee one finish informing their reports.

Constraints

  • 1 <= n <= 100000
  • manager forms one rooted organization tree
  • 0 <= informTime[i] <= 1000
  • the answer fits a signed 32-bit integer

More Amazon problems

See Amazon hiring insights
public int minutesToInformEveryone(int n, int headId, int[] manager, int[] informTime) {
    // Write your code here.
}
n6
headId2
manager[2,2,-1,2,2,2]
informTime[0,0,1,0,0,0]
expected1
Checking account…