Reach a Meeting by Scheduled Trains
Updated
Problem statement
A timetable contains directed train rides. Ride i leaves city origins[i] at time departures[i], reaches city destinations[i] at time arrivals[i], and may be used at most once.
You begin in start at startTime. You may wait in any city for any nonnegative amount of time. You may board a ride when you are in its origin city at or before its departure time.
Return true if you can reach destination no later than meetingTime. Otherwise, return false.
A transfer is allowed when one ride arrives at the exact time that the next ride departs. If start already equals destination, reaching the meeting depends only on whether startTime is no later than meetingTime.
Function
canReachMeeting(origins: String[], departures: int[], destinations: String[], arrivals: int[], start: String, startTime: int, destination: String, meetingTime: int) → booleanExamples
Example 1
origins = ["A","B","A"]departures = [1,5,3]destinations = ["B","C","C"]arrivals = [4,7,10]start = "A"startTime = 0destination = "C"meetingTime = 8return = trueTake the ride from A to B, arriving at 4, then take the ride from B to C, arriving at 7.
Example 2
origins = ["A","B","A"]departures = [1,5,3]destinations = ["B","C","C"]arrivals = [4,7,10]start = "A"startTime = 0destination = "C"meetingTime = 6return = falseThe earliest possible arrival in C is time 7, which is after the meeting time.
Example 3
origins = ["A","B"]departures = [2,5]destinations = ["B","C"]arrivals = [5,6]start = "A"startTime = 2destination = "C"meetingTime = 6return = trueYou board the first ride exactly at startTime. It arrives in B at time 5, allowing an exact-time transfer to the second ride.
Constraints
1 <= origins.length <= 2 * 10^5.origins.length == departures.length == destinations.length == arrivals.length.- Every city name is nonempty and contains at most
30letters or digits. 0 <= departures[i] <= arrivals[i] <= 10^9.0 <= startTime, meetingTime <= 10^9.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
- Path With Maximum ProbabilitySalesforce · ONSITE INTERVIEWSalesforce interview questions
- Cheapest Flights Within K StopsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Dijkstra's Shortest PathsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Single-Source Shortest PathsRippling · ONSITE INTERVIEWRippling interview questions
- Hub Vertices Within a RadiusThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Minimum Path Cost with Edge DiscountsSkyscanner · ONSITE INTERVIEWSkyscanner interview questions
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions