Code Room
CodingHardcod-g749
Subject Shortest pathLevel Senior–Staff~40 minCommon in Algorithms & data structures interviewsIndustries Software development, Telecom

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.