Katkat

Identify Unique Unordered City Pairs in Flight Log

AmazonBusiness Intelligence Engineer · Onsite

Last 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.