Trains the technique from
LeetCode 1376Time Needed to Inform All EmployeesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A brigade has count members numbered 0 through count - 1. The chain of command is given as an array: supervisor[i] is the number of the member who supervises member i, except that supervisor[lead] == -1 because the lead answers to nobody. Following the links upwards from any member always arrives at the lead, so the chain of command forms a tree rooted there.
When a member learns of an alert, they spend relayTime[i] minutes passing it on, after which all of the members they directly supervise know it at the same moment. A member who supervises nobody has relayTime[i] == 0.
The lead learns of the alert at minute 0. Return the number of minutes that pass before every member of the brigade knows.
Example 1
Members 1 and 2 both hear the alert at minute 1. Members 3 and 4 hear it 2 minutes after that, at minute 3, and members 5 and 6 hear it 5 minutes after minute 1, at minute 6, by which point the whole brigade knows.
Example 2
The chain runs 0 to 1 to 2 to 3, so member 1 hears it at minute 3, member 2 at minute 5 and member 3 at minute 6.
Example 3
The lead is member 3 and supervises the other four directly, spending no time on the relay, so everybody knows at minute 0.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def alert_minutes(count: int, lead: int, supervisor: list[int], relayTime: list[int]) -> int:public int alertMinutes(int count, int lead, int[] supervisor, int[] relayTime)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.