A travel site lists flights as tuples (code, price, stops, minutes). A traveller will accept at most max_stops stops. Among the acceptable flights, the best one is the cheapest; if several cost the same, the one with fewer minutes in the air wins; if that also ties, the one whose code comes first alphabetically.
Write best_flight(flights, max_stops) that returns the code of the best flight, or None if no flight is acceptable.
Examples
Input: flights = [("AZ12", 240, 1, 410), ("BX7", 199, 2, 520), ("CQ3", 240, 0, 385)], max_stops = 1
Output: "CQ3"
Explanation: BX7 has too many stops. AZ12 and CQ3 cost the same, and CQ3 is shorter.
Input: flights = [("AZ12", 240, 1, 410)], max_stops = 0
Output: None
Constraints
0 <= len(flights) <= 10**5- Codes are distinct; prices, stops and minutes are non-negative integers.
Goals
- Choose the best item with `min(..., key=...)` instead of a hand-written loop
- Break ties with a tuple key
- Handle the case where nothing qualifies with `default=`