The Airport With the Most Traffic - Problem

Given a Flights table containing flight traffic data between airports, find the airport(s) with the most total traffic.

The airport with the most traffic is defined as the airport that has the largest total number of flights that either departed from or arrived at that airport.

If there are multiple airports tied for the most traffic, return all of them.

  • Each row represents flights between two airports with the flight count
  • An airport's total traffic = sum of all flights departing from it + sum of all flights arriving at it
  • Return results in any order

Table Schema

Flights
Column Name Type Description
departure_airport PK int ID of the departure airport
arrival_airport PK int ID of the arrival airport
flights_count int Number of flights from departure to arrival airport
Primary Key: (departure_airport, arrival_airport)
Note: Each row represents flight traffic between two specific airports

Input & Output

Example 1 — Multiple Airports with Different Traffic
Input Table:
departure_airport arrival_airport flights_count
1 2 150
2 1 100
2 3 200
Output:
airport_id
2
💡 Note:

Airport traffic calculation: Airport 1 has 150 (departure) + 100 (arrival) = 250 total flights. Airport 2 has 100 + 200 (departures) + 150 (arrival) = 450 total flights. Airport 3 has 0 (departure) + 200 (arrival) = 200 total flights. Airport 2 has the highest traffic with 450 flights.

Example 2 — Tied for Maximum Traffic
Input Table:
departure_airport arrival_airport flights_count
1 2 100
2 1 100
1 3 50
3 2 50
Output:
airport_id
1
2
💡 Note:

Airport 1 has 100 + 50 (departures) + 100 (arrival) = 250 total flights. Airport 2 has 100 (departure) + 100 + 50 (arrivals) = 250 total flights. Airport 3 has 50 (departure) + 50 (arrival) = 100 total flights. Airports 1 and 2 are tied with 250 flights each, so both are returned.

Constraints

  • 1 ≤ departure_airport, arrival_airport ≤ 1000
  • 1 ≤ flights_count ≤ 10000
  • departure_airport ≠ arrival_airport

Visualization

Tap to expand
Airport With Most Traffic INPUT Flights Table departure arrival flights LAX JFK 100 JFK ORD 150 ORD LAX 200 JFK LAX 50 Airport Network LAX JFK ORD ALGORITHM STEPS 1 UNION departure + arrival Combine both columns as source 2 SUM flights per airport GROUP BY airport Traffic Totals: LAX: 100+200+50 = 350 JFK: 100+150+50 = 300 ORD: 150+200 = 350 3 Find MAX traffic MAX(total) = 350 4 Filter airports with MAX WHERE total = 350 HAVING SUM(flights) = (SELECT MAX...) FINAL RESULT Airports with Most Traffic LAX ORD 350 flights each Output Table airport LAX ORD OK - TIE HANDLED Both airports returned Traffic Comparison LAX: 350 JFK: 300 ORD: 350 Key Insight: Use UNION ALL to combine departures and arrivals, treating each flight record twice - once for departure airport and once for arrival. Then GROUP BY airport and SUM the flights. Use subquery with MAX to find ties. SELECT airport FROM (...UNION ALL...) GROUP BY airport HAVING SUM(flights) = (SELECT MAX(total)...) TutorialsPoint - The Airport With the Most Traffic | Optimal Solution
Asked in
Amazon 12 Microsoft 8 Google 6
18.5K Views
Medium Frequency
~12 min Avg. Time
895 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen