Time to Inform Every Employee
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[]) → intExamples
Example 1
n = 6headId = 2manager = [2,2,-1,2,2,2]informTime = [0,0,1,0,0,0]return = 1The head directly informs every other employee in one minute.
Example 2
n = 4headId = 0manager = [-1,0,0,1]informTime = [2,3,0,0]return = 5The deepest recipient is reached after the head and employee one finish informing their reports.
Constraints
1 <= n <= 100000manager forms one rooted organization tree0 <= informTime[i] <= 1000the answer fits a signed 32-bit integer