Reach a Destination Through Scheduled Flights
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks most first attempts at this Google OA problem is treating it as plain graph reachability. Reported in October 2026, it gives you airports and timed flights, and asks if you can get from a start airport to a target. Ignore the clock and you'll return true on routes that are impossible. It's a graph problem with time attached, so edges only count when the departure fits your current arrival. If you blank on the ordering logic mid-assessment, StealthCoder runs invisibly on your desktop and gives you a working solution as a safety net.
The problem
There are airportCount airports numbered from 0 through airportCount - 1. Each flight is [origin, destination, departureTime, arrivalTime]. You begin at startAirport at time 0. You may take a flight from your current airport when its departure time is at least your current arrival time. After taking it, your current time becomes its arrival time. Examples Example 1 airportCount = 3 flights = [[0,1,2,5],[1,2,5,8]] startAirport = 0 targetAirport = 2 return = true Take the first flight and arrive at airport 1 at time 5. The second flight departs exactly at time 5, so the connection is valid.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that time only moves forward, so the earliest arrival at each airport is the only number that matters. Arriving earlier never hurts, because any flight you could catch later, you could also catch earlier. That makes this a Dijkstra-style search on earliest arrival time, or a simpler sort. Sort flights by departure time, set best[start] = 0, then scan: if best[origin] <= departure, update best[destination] = min(best[destination], arrival). Check the target at the end. The pitfall is a plain BFS or DFS with a visited set. It marks an airport visited at a late time and blocks a better early arrival. Also keep the comparison inclusive, since the example departs exactly at arrival time 5. One caveat: if a flight's arrival can be earlier than its departure in the data, the single sorted pass needs care. If you freeze live, StealthCoder is the hedge that writes it out for you.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Reach a Destination Through Scheduled Flights cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Reach a Destination Through Scheduled Flights FAQ
What's the trick to the Google flights OA question?+
Track the earliest arrival time per airport instead of a visited flag. Time only moves forward, so arriving earlier is never worse. A plain visited set can block a better route that reaches the same airport sooner, which is the classic first-attempt bug.
Is the connection check strict or inclusive?+
Inclusive. The example has a flight arriving at time 5 and the next one departing at time 5, and it's valid. Use departure >= current arrival. Writing a strict greater-than will fail that exact sample and likely several hidden tests.
Do I need Dijkstra or is sorting enough?+
Sorting flights by departure time and doing one pass with a best-arrival array works when flights move forward in time. Dijkstra with a min-heap on arrival time is the safer general version. Either gives the right answer, so pick the one you can code cleanly.
What edge cases should I test?+
Start equals target, which should return true. Also test no flights at all, a flight departing before you can reach its origin, and two routes to the same airport with different arrival times. The earlier arrival must win.
How do I prepare for this in 48 hours?+
Practice one earliest-arrival or shortest-path-with-constraints problem, then write this one from scratch. Focus on the state you store per node and why earliest time dominates. Know the sorted-scan version and the heap version, so you have a fallback if one fails.