Find a User’s Airport from Flight History
Updated
Problem statement
Given flight records, a user ID, and a time, return that user's location at that time. Each row in flights is [departureAirport, departureTime, arrivalAirport, arrivalTime, userId]. Times in a row are decimal integer strings; time is an integer in the same units.
For this exercise, assume each user's flights form one connected journey. Flights do not overlap, and each flight starts at the airport where the previous flight ended. The input rows may appear in any order.
- Before the user's first departure, return that flight's departure airport.
- During a flight, including its departure time and excluding its arrival time, return
IN_TRANSIT. - From an arrival until the next departure, return the arrival airport. After the last arrival, return the final airport.
- If one flight arrives exactly when the next departs, the user is already in transit on the next flight.
- If the user has no flight records, return
UNKNOWN.
Ignore flights belonging to other users. Return the airport code or the exact sentinel string described above.
Function
airportAtTime(flights: String[][], userId: String, time: int) → StringExamples
Example 1
flights = [["SFO","10","LAX","20","alice"],["LAX","30","JFK","50","alice"],["SEA","5","DEN","15","bob"]]userId = "alice"time = 25return = "LAX"Alice has arrived at LAX at time 20 and does not leave until time 30.
Example 2
flights = [["LAX","20","JFK","40","alice"],["SFO","10","LAX","20","alice"]]userId = "alice"time = 20return = "IN_TRANSIT"The first flight arrives at time 20, exactly when the next flight departs. The departure boundary belongs to the next flight.
Example 3
flights = [["SFO","10","LAX","20","alice"],["LAX","30","JFK","50","alice"],["SEA","5","DEN","15","bob"]]userId = "carol"time = 100return = "UNKNOWN"There are no flight records for carol.
Constraints
0 <= flights.length <= 10^5.- Every flight row contains exactly
5strings. - Each airport code and user ID contains
1to32uppercase or lowercase English letters or digits. - Airport codes never equal
IN_TRANSITorUNKNOWN. - All times are integers from
0through10^9, and each departure time is strictly less than its arrival time. - For each user, sorting by departure time gives non-overlapping flights with matching consecutive arrival and departure airports. Consecutive flights may share a boundary time.
More Ramp interview questions
- Retryable URL MazePHONE SCREEN · Seen Oct 2026
- Count Overlapping Square PairsOA · Seen Nov 2026
- Count User Mentions in Chat MessagesOA · Seen Nov 2026
- Accept or Decline QueriesOA · Seen Sep 2026
- Detect Recurring Transactions with Tunable TolerancesONSITE INTERVIEW · Seen Jul 2026
- Recipe Management SystemOA · Seen Mar 2026
- Task Manager with Timed AssignmentsOA · Seen Jan 2026
- Bank Requests with Delayed CashbackOA · Seen Dec 2025
- Convert Snake Case Variables to Camel CaseOA · Seen Apr 2025
- Correct Apartment Bedroom CountsOA · Seen Feb 2025
Similar questions at other companies
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Asteroid CollisionSiemens · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions