Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 1.08 KB

_1376. Time Needed to Inform All Employees.md

File metadata and controls

39 lines (26 loc) · 1.08 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : October 26, 2024

Last updated : October 26, 2024


Related Topics : Tree, Depth-First Search, Breadth-First Search

Acceptance Rate : 60.18 %


Solutions

Python

class Solution:
    def numOfMinutes(self, n: int, headID: int, manager: List[int], informTime: List[int]) -> int:
        subs = defaultdict(list)
        for i, m in enumerate(manager) :
            subs[m].append(i)

        def dfs(subs: dict, informTime: List[int] = informTime, curr: int = headID) -> int :
            return informTime[curr] + max([dfs(subs, informTime, x) for x in subs[curr]] + [0])

        return dfs(subs)