Code RoomTraffic signal shortest arrival
HardPrep Room Coding #1314

Traffic signal shortest arrival

CodingAlgorithms & data structuresSenior–Staff~40 min

A courier travels a road network of n intersections (0..n-1) connected by bidirectional `roads` `[u, v, travel_time]`. Every intersection has a synchronized signal: during the first `red_period` time units of each `2*red_period` cycle it is green (you may depart), and during the second half it is red (you must wait at the intersection until the next green). The courier starts at intersection 0 at time 0 (green) and wants to reach intersection n-1. Return the earliest arrival time, or -1 if unreachable. Arriving at an intersection is always allowed; only departing is gated.

Implement
min_time_signals(n: int, roads: list[list[int]], red_period: int) → int
Examples
in[3,[[0,1,7],[1,2,4]],5]out14
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 40 min
InputExpectedGot
[3,[[0,1,7],[1,2,4]],5]14not run yetsample