Earliest Arrival on a Road Network With Signalized Intersections

Last updated: November 29, 2026

Quick Overview

Given a directed road graph with travel times and some intersections controlled by fixed-cycle traffic signals (leaving only during the green part of each cycle), find the earliest arrival time from a source to a destination for a given departure time.

Applied Intuition
Coding & Algorithms
Software Engineer
Applied Intuition
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a directed road graph with travel times and some intersections controlled by fixed-cycle traffic signals (leaving only during the green part of each cycle), find the earliest arrival time from a source to a destination for a given departure time.

Simulation at Applied Intuition models traffic signals and route timing for scenario generation and planning tests. The interviewer checks Dijkstra adapted to time-dependent waiting and, crucially, the FIFO argument that makes it still correct.

What the Interviewer Expects
  • Model waiting at a signal as a function of arrival time
  • Compute the next green start with modular arithmetic
  • Run Dijkstra on arrival times with lazy deletion
  • Argue the FIFO property: arriving later never lets you leave earlier
  • Handle unreachable destinations
Key Topics to Cover
Dijkstra
time-dependent shortest path
modular arithmetic
FIFO property
weighted graphs
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What breaks if waiting voluntarily could help, and how would you handle it?
  • How would you add a penalty for each red light encountered?
  • How would you precompute for many queries on the same map?
  • How would you model signals with offsets between intersections (green waves)?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

roads are directed (u, v, seconds). signals[v] = (cycle, green): departures from v allowed when t mod cycle < green. Unsignaled nodes never wait. Waiting only happens at signals. Return earlie...

High-Level Design

Labels are arrival times. From node u at time t, the departure time is t if green, otherwise t + cycle - t mod cycle. Each edge then gives arrival = departure + w. The departure function is non-de...


Submit Your Answer
Markdown supported