Second Fastest Arrival Through a Network of Timed Signals

Last updated: November 29, 2026

Quick Overview

In an undirected graph of nodes 1..n, every edge takes the same travel time, and all signals switch between green and red every change minutes starting green. You can leave a node only on green; return the strictly second smallest possible arrival time at node n.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


In an undirected graph of nodes 1..n, every edge takes the same travel time, and all signals switch between green and red every change minutes starting green. You can leave a node only on green; return the strictly second smallest possible arrival time at node n.

A Meta onsite stretch problem where the interviewer wants you to reduce a time-based puzzle to a graph property. Framed as a packet crossing switches with fixed duty cycles. The key insight is that arrival time is monotone in hop count, so the second fastest time corresponds to the second smallest distinct path length.

What the Interviewer Expects
  • Notice all edges share one travel time, so time depends only on hop count
  • Argue that time is strictly increasing in hop count
  • Run BFS tracking the first and second distinct distances per node
  • Simulate the signal waits for the chosen hop count
  • Explain why revisiting nodes (bouncing) is allowed
Key Topics to Cover
BFS
Second shortest path
Simulation
Graph theory
Modular timing
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
  • Why can the second smallest length be first + 2 but never larger?
  • What if edges had different travel times?
  • How would you return the k-th fastest time?
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
  • n up to 10^4, edges up to 2 * 10^4, connected graph.
  • Walks may repeat nodes and edges.
  • Return the second smallest strictly greater arrival time....
High-Level Design

Since the wait at each node depends only on the current time, the total time is a strictly increasing function of the number of hops. So find the second smallest distinct walk length from 1 to n, then...


Submit Your Answer
Markdown supported