Time Needed to Inform All Employees
Description
You are given a list of employees as tuples (id, manager_id, delay).
The CEO is identified by manager_id == -1. `delay` on each employee is
the time that employee takes to inform their direct reports (so the
CEO's delay is the time before the CEO's reports receive the email).
When a manager receives the email, they take `delay` minutes to inform
all of their direct reports (informing happens in parallel — every
direct report receives it at the same moment, `delay` minutes later).
Each report then independently informs their own subordinates after
their own delay. Leaves have no one to inform, so their delay does not
contribute.
Return the total number of minutes until every employee has been
informed — equivalently, the maximum weighted root-to-leaf path in the
management tree, where edge weight is the parent's delay.
Example:
employees = [
(0, -1, 5), # CEO, takes 5 min to inform reports
(1, 0, 3), # report of CEO, takes 3 to inform their reports
(2, 0, 1), # report of CEO, takes 1
(3, 1, 0), # leaf under 1
(4, 2, 0), # leaf under 2
]
Path to 3: 5 + 3 = 8
Path to 4: 5 + 1 = 6
-> 8
Edges to watch:
- The input order is arbitrary — don't assume index == id or that
parents appear before children.
- Leaf delay is irrelevant (no one to inform).
- The tree may be a single node (just the CEO) -> 0. Constraints
- Exactly one employee has manager_id == -1 (the CEO) - ids are unique - The structure is a tree (no cycles, every non-CEO has exactly one manager) - delay >= 0 - 1 <= len(employees)
solution.py
output
Run the cases to see results here.