Skip to content

Commit

Permalink
The Airport With the Most Traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
hikjik committed Jan 25, 2024
1 parent ca63df7 commit bf668ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions PROBLEM_LIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,7 @@
| 2102. | [Sequentially Ordinal Rank Tracker](https://leetcode.com/problems/sequentially-ordinal-rank-tracker/) | [C++](./solutions/sequentially-ordinal-rank-tracker/solution.hpp) | <img src='https://img.shields.io/badge/Hard-darkred?style=flat-square'/> | | <img src='https://img.shields.io/badge/Design-51337f?style=flat-square'/> <img src='https://img.shields.io/badge/Heap (Priority Queue)-71337f?style=flat-square'/> <img src='https://img.shields.io/badge/Data Stream-4a7f33?style=flat-square'/> <img src='https://img.shields.io/badge/Ordered Set-7f3360?style=flat-square'/> | |
| 2103. | [Rings and Rods](https://leetcode.com/problems/rings-and-rods/) | [C++](./solutions/rings-and-rods/solution.hpp) | <img src='https://img.shields.io/badge/Easy-darkgreen?style=flat-square'/> | | <img src='https://img.shields.io/badge/Hash Table-7f337a?style=flat-square'/> <img src='https://img.shields.io/badge/String-7f334c?style=flat-square'/> | |
| 2108. | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array/) | [C++](./solutions/find-first-palindromic-string-in-the-array/solution.hpp) | <img src='https://img.shields.io/badge/Easy-darkgreen?style=flat-square'/> | | <img src='https://img.shields.io/badge/Array-57337f?style=flat-square'/> <img src='https://img.shields.io/badge/Two Pointers-7f6633?style=flat-square'/> <img src='https://img.shields.io/badge/String-7f334c?style=flat-square'/> | |
| 2112. | [The Airport With the Most Traffic 🔒](https://leetcode.com/problems/the-airport-with-the-most-traffic/) | [SQL](./extra/sql/the-airport-with-the-most-traffic/solution.sql), [PY](./extra/pandas/the-airport-with-the-most-traffic/solution.py) | <img src='https://img.shields.io/badge/Medium-darkorange?style=flat-square'/> | | <img src='https://img.shields.io/badge/Database-337c7f?style=flat-square'/> | |
| 2114. | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/) | [C++](./solutions/maximum-number-of-words-found-in-sentences/solution.hpp) | <img src='https://img.shields.io/badge/Easy-darkgreen?style=flat-square'/> | | <img src='https://img.shields.io/badge/Array-57337f?style=flat-square'/> <img src='https://img.shields.io/badge/String-7f334c?style=flat-square'/> | |
| 2118. | [Build the Equation 🔒](https://leetcode.com/problems/build-the-equation/) | [SQL](./extra/sql/build-the-equation/solution.sql), [PY](./extra/pandas/build-the-equation/solution.py) | <img src='https://img.shields.io/badge/Hard-darkred?style=flat-square'/> | | <img src='https://img.shields.io/badge/Database-337c7f?style=flat-square'/> | |
| 2119. | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal/) | [C++](./solutions/a-number-after-a-double-reversal/solution.hpp) | <img src='https://img.shields.io/badge/Easy-darkgreen?style=flat-square'/> | | <img src='https://img.shields.io/badge/Math-7f5933?style=flat-square'/> | |
Expand Down
16 changes: 16 additions & 0 deletions extra/pandas/the-airport-with-the-most-traffic/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd


def airport_with_most_traffic(flights: pd.DataFrame) -> pd.DataFrame:
return (
pd.concat(
[
flights.rename(columns={"departure_airport": "airport_id"}),
flights.rename(columns={"arrival_airport": "airport_id"}),
]
)
.groupby("airport_id")
.flights_count.sum()
.reset_index(name="total")
.query("total == total.max()")[["airport_id"]]
)
17 changes: 17 additions & 0 deletions extra/sql/the-airport-with-the-most-traffic/solution.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH Airports AS (
SELECT departure_airport AS airport_id,
flights_count
FROM Flights
UNION ALL
SELECT arrival_airport AS airport_id,
flights_count
FROM Flights
), RankedAirports AS (
SELECT airport_id,
RANK() OVER(ORDER BY SUM(flights_count) DESC) AS rnk
FROM Airports
GROUP BY airport_id
)
SELECT airport_id
FROM RankedAirports
WHERE rnk = 1;

0 comments on commit bf668ff

Please sign in to comment.