Minimum Total Layover Wait
Updated
Problem statement
There are airportCount airports numbered 0 through airportCount - 1. Each flight is [origin, destination, departureTime, arrivalTime].
You start at startAirport at time 0. You may board a flight at your current airport when its departure time is at least the time you got there; after the flight you are at its destination at its arrival time.
A connection is a change from one flight to the next. Its waiting time is the next flight's departure time minus the previous flight's arrival time. Time spent at startAirport before your first flight does not count. The total waiting time of a route is the sum over all of its connections, so a route with a single flight waits 0.
Examples
Example 1
airportCount = 3flights = [[0,1,1,3],[0,1,5,6],[1,2,7,9]]startAirport = 0targetAirport = 2return = 1- Taking flight
[0, 1, 1, 3]reaches airport1at time3; the flight to airport2leaves at7, so the wait is7 - 3 = 4. - Taking the later flight
[0, 1, 5, 6]reaches airport1at time6, and the wait is only7 - 6 = 1. Waiting at the start airport before the first flight does not count. - The smallest total wait is
1.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.
More Google Phone Screen questions
- 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
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Boards to Cover Roof HolesPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Platform Referral RewardsScale AI · OAScale AI interview questions
- Shipping Starts and Terminal DestinationsIntuit · OAIntuit 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
- Longest Name Chain in a Directed Acyclic GraphOscar Health · PHONE SCREEN
- Service Dependency Load FactorsRobinhood · PHONE SCREENRobinhood interview questions
Google interview experiences
- Google L4 SWE Phone Screen: 1 Experience
- Google ML Engineering Manager Onsite: 1 Experience
- Google Experienced SWE First Round and Onsite: 1 Experience
- Google AI Coding Interview and AI OA: 2 Experiences
- Google SWE Intern Interview Results Timeline: 13 Experiences
- Google L4 SWE Phone Screen and Kirkland Onsite: 1 Experience