Time Needed to Inform All Employees
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A company has n employees with IDs 0 to n - 1. The head of the company is headID. For every employee i, manager[i] is their direct manager; manager[headID] = -1. The reporting structure is guaranteed to form a tree.
The head wants to share urgent news. Once employee i learns it, they spend informTime[i] minutes to tell all of their direct reports at once, who then start passing it on in the same way. Employees with no reports have informTime[i] = 0.
Return the number of minutes until every employee has been informed.
Examples
Constraints
- 1 <= n <= 10^5
- 0 <= headID < n
- manager.length == n and informTime.length == n
- 0 <= informTime[i] <= 1000; informTime[i] == 0 if employee i has no reports
- The management structure is a tree rooted at headID
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.