Track Users From Flight History
RampSoftware Engineer · Technical ScreenLast updated
This question evaluates competency in processing and aggregating temporal event data, including time-interval reasoning, counting/grouping per user, and designing efficient data structures and algorithms for large datasets.
You are given an unsorted list of flight records. Each record contains departure_airport, departure_time, arrival_airport, arrival_time, and user_id.
Assume:
- Timestamps are ISO-8601 UTC strings.
- Flights for the same user do not overlap.
- A user's status at a given time is:
unknownbefore their first recorded departure,in_transit(departure_airport, arrival_airport)between departure and arrival,- the airport where they most recently landed or are waiting to depart between two flights.
Implement two functions:
get_user_with_most_flights(flights): return theuser_idwith the largest number of flight records. If multiple users tie, return any one of them.get_user_locations(flights, time): given a timestamp, return the location or travel status of every user at that time.
Your solution should handle large inputs efficiently.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.