Big Countries — LeetCode 595 Python Solution
EasyDatabase
- Problem
- #595
- Reading time
- 2 min
- Source
- leetcode.com
The problem
A country is big when its area is at least 3,000,000 or its population is at least 25,000,000. Report the name, population and area of every big country, in any order. The World table has one row per country: name (varchar, the primary key), continent (varchar), area (int), population (int) and gdp (bigint).
Example
World table: | name | continent | area | population | gdp | | --------- | ------------- | ------- | ---------- | ------------- | | Argentina | South America | 2780400 | 45376763 | 445445000000 | | Belgium | Europe | 30528 | 11589623 | 529606710000 | | Brazil | South America | 8515767 | 212559417 | 1839758000000 | | Croatia | Europe | 56594 | 4105267 | 60752000000 | | Egypt | Africa | 1010408 | 102334404 | 363069000000 | Result: | name | population | area | | --------- | ---------- | ------- | | Argentina | 45376763 | 2780400 | | Brazil | 212559417 | 8515767 | | Egypt | 102334404 | 1010408 | Argentina and Egypt qualify on population alone, Brazil qualifies on both tests, and Belgium and Croatia fail both.
Python solution
Python
import pandas as pd
def big_countries(world: pd.DataFrame) -> pd.DataFrame:
res = world[(world['area'] >= 3000000) | (world['population'] >= 25000000)]
return res[['name', 'population', 'area']]Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 595. Big Countries?
- LeetCode 595. Big Countries is rated Easy on LeetCode.
- What topics does LeetCode 595. Big Countries cover?
- LeetCode 595. Big Countries is tagged Database on LeetCode.