Skip to content

Commit 9b9af91

Browse files
committed
Added Python solution for "Time Needed to Inform All Employees"
1 parent 5188fa0 commit 9b9af91

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from collections import defaultdict
2+
from typing import List
3+
4+
5+
class Solution:
6+
"""
7+
Time: O(n)
8+
Memory: O(n)
9+
"""
10+
11+
def numOfMinutes(self, n: int, head_id: int, manager: List[int], inform_time: List[int]) -> int:
12+
def dfs(boss: int) -> int:
13+
return inform_time[boss] + max((dfs(emp) for emp in subordinates[boss]), default=0)
14+
15+
subordinates = defaultdict(set)
16+
17+
for u, v in enumerate(manager):
18+
subordinates[v].add(u)
19+
20+
return dfs(head_id)
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)