EasyNo. 0595
Big Countries — LeetCode 595 Python Solution
- Topics
- Database
- 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
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
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0596 | Classes With at Least 5 Students | Easy |
| 0601 | Human Traffic of Stadium | Hard |
| 0602 | Friend Requests II: Who Has the Most Friends | Medium |
| 0586 | Customer Placing the Largest Number of Orders | Easy |
| 0585 | Investments in 2016 | Medium |
| 0175 | Combine Two Tables | Easy |
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.