Leetcode 1492 Solution

This article provides solution to leetcode question 1492 (time-needed-to-inform-all-employees)

https://leetcode.com/problems/time-needed-to-inform-all-employees

Solution

class Solution: def numOfMinutes(self, n: int, headID: int, manager: List[int], informTime: List[int]) -> int: graph = collections.defaultdict(list) for i, mgr in enumerate(manager): graph[mgr].append(i)
q = collections.deque() q.append((headID, 0))
ans = 0 while q: emp_id, t = q.popleft()
ans = max(ans, t)
for report_id in graph[emp_id]: q.append((report_id, t + informTime[emp_id]))
return ans