Identify Unique Unordered City Pairs in Flight Log
AmazonBusiness Intelligence Engineer · OnsiteLast updated
This question evaluates competency in data manipulation, deduplication of symmetric relationships, and handling unordered pairs within relational or tabular datasets using SQL or Python/Pandas.
FLIGHTS
+----------------+---------------+ | departure_city | arrival_city | +----------------+---------------+ | NYC | LAX | | LAX | NYC | | ORD | ATL | +----------------+---------------+
Scenario
You work with an airline flight log. Each row records a flight’s origin and destination city. Management wants to see all distinct city pairs regardless of flight direction (NYC–LAX is the same as LAX–NYC).
Question
Write a SQL query (or equivalent Python/Pandas snippet) that returns the unique unordered city pairs from the FLIGHTS table, treating (A,B) and (B,A) as the same route combination.
Hints
Normalize the order of the two cities—e.g., use LEAST/GREATEST or sort values—then GROUP BY the normalized pair.
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.