Find Traveler's Current Airport
Implement solve(flights, queries).
Design a service that answers where a traveler is located at a given UTC moment. You are given flights and a query containing userId and time. For the requested user and timestamp, return the IATA airport code where that user is located.
Each record in flights is a list of five strings in this fixed order:
[departureAirport, departureTime, arrivalAirport, arrivalTime, userId]
departureAirport and arrivalAirport are IATA codes such as "SFO" or "JFK".departureTime and arrivalTime are ISO 8601 UTC datetime strings such as "2021-10-26T16:15:00Z".userId is a numeric user identifier stored as a string.Location is determined by these rules:
"".time comes before that user's first departureTime, return the first flight's departureAirport.departureTime[i] <= time < arrivalTime[i], return "".arrivalTime[i] <= time < departureTime[i + 1], return arrivalAirport[i].arrivalTime, return that final arrivalAirport.Example 1:
Input:
flights = [["SFO", "2021-10-26T16:15:00Z", "JFK", "2021-10-26T21:34:00Z", "1"],
["JFK", "2021-10-29T18:31:00Z", "MIA", "2021-10-29T21:36:00Z", "1"],
["MIA", "2021-11-15T15:10:00Z", "MSY", "2021-11-15T18:21:00Z", "1"],
["SFO", "2021-10-28T11:47:00Z", "SEA", "2021-10-28T14:02:00Z", "2"],
["SEA", "2021-11-04T03:47:00Z", "JFK", "2021-11-04T09:12:00Z", "2"]]
userId = 1
time = "2021-10-26T15:00:00Z"
Output: "SFO"
Explanation: At 15:00 UTC, user 1's first flight has not yet departed from SFO, so the traveler is still at the departure airport.
Example 2:
Input:
flights = [["BOS", "2023-01-05T06:00:00Z", "DFW", "2023-01-05T10:00:00Z", "2"], ["DFW", "2023-01-08T12:00:00Z", "SEA", "2023-01-08T15:00:00Z", "2"]]
userId = 2
time = "2023-01-06T12:00:00Z"
Output: "DFW"
Example 3:
Input:
flights = [["SFO", "2021-10-26T16:15:00Z", "JFK", "2021-10-26T21:34:00Z", "1"]]
userId = 99
time = "2021-10-26T15:00:00Z"
Output: ""
Constraints:
1 <= flights.size() <= 10^5userId is a positive integer between 1 and 10^9.departureTime < arrivalTime.departureTime, flight intervals do not overlap.