Reach a Destination Through Scheduled Flights
Updated
Problem statement
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.
Return whether some valid sequence of flights reaches targetAirport. Taking zero flights is allowed when the start and target are equal.
Function
canReachDestination(airportCount: int, flights: int[][], startAirport: int, targetAirport: int) → booleanExamples
Example 1
airportCount = 3flights = [[0,1,2,5],[1,2,5,8]]startAirport = 0targetAirport = 2return = trueTake the first flight and arrive at airport 1 at time 5. The second flight departs exactly at time 5, so the connection is valid.
Example 2
airportCount = 3flights = [[0,1,2,6],[1,2,5,8]]startAirport = 0targetAirport = 2return = falseYou reach airport 1 at time 6, after its only outgoing flight has departed.
Example 3
airportCount = 4flights = [[1,3,8,10],[0,2,1,4],[2,1,5,7],[0,1,9,12]]startAirport = 0targetAirport = 3return = trueAlthough the input is unsorted, flights 0→2, 2→1, and 1→3 form a valid itinerary arriving at time 10.
Constraints
1 <= airportCount <= 100000.0 <= flights.length <= 100000.- Every flight has four integers
[origin, destination, departureTime, arrivalTime]. 0 <= origin, destination < airportCount.0 <= departureTime < arrivalTime <= 1000000000.0 <= startAirport, targetAirport < airportCount.
More Google Phone Screen questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Platform Referral RewardsScale AI · OAScale AI interview questions
- Shipping Starts and Terminal DestinationsIntuit · OAIntuit interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
- Deterministic Secret Santa AssignmentShopify · PHONE SCREENShopify interview questions
- Minimum Traveling Salesperson TourGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Minimum Completion Time for DAG DependenciesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Work Order Critical PathHadrian · PHONE SCREENHadrian interview questions
- Top-Down Employee Reporting ForestOkta · ONSITE INTERVIEWOkta interview questions