Big Countries - Problem

Given a World table with information about countries, find all the big countries.

A country is considered big if:

  • It has an area of at least 3,000,000 km², OR
  • It has a population of at least 25,000,000

Return the name, population, and area of all big countries in any order.

Table Schema

World
Column Name Type Description
name PK varchar Country name (primary key)
continent varchar Continent where the country is located
area int Country area in km²
population int Country population
gdp bigint Country GDP value
Primary Key: name
Note: Each row represents a country with its geographical and economic information

Input & Output

Example 1 — Mixed Big Countries
Input Table:
name continent area population gdp
Afghanistan Asia 652230 25500100 20343000000
Albania Europe 28748 2831741 12960000000
Algeria Africa 2381741 37100000 188681000000
Output:
name population area
Afghanistan 25500100 652230
Algeria 37100000 2381741
💡 Note:

Afghanistan qualifies because its population (25,500,100) is ≥ 25,000,000, even though its area is less than 3,000,000 km². Algeria qualifies because its population (37,100,000) is ≥ 25,000,000. Albania is excluded because both its area (28,748) and population (2,831,741) are below the thresholds.

Example 2 — Large Area, Small Population
Input Table:
name continent area population gdp
Russia Europe 17098242 146793744 1699876578000
Kazakhstan Asia 2724900 18776707 236635000000
Output:
name population area
Russia 146793744 17098242
💡 Note:

Russia qualifies on both criteria: area (17,098,242) ≥ 3,000,000 km² AND population (146,793,744) ≥ 25,000,000. Kazakhstan is excluded because its population (18,776,707) is less than 25,000,000 and its area (2,724,900) is less than 3,000,000 km².

Constraints

  • 1 ≤ World table rows ≤ 200
  • name is unique for each country
  • area and population are non-negative integers

Visualization

Tap to expand
Big Countries - SQL Query Problem INPUT: World Table name pop area China 1.4B 9.6M USA 331M 9.8M Vatican 800 0.44 Russia 144M 17.1M India 1.38B 3.3M Big Country Criteria: area >= 3,000,000 km² OR population >= 25,000,000 Return: name, population, area ALGORITHM STEPS 1 SELECT Columns name, population, area 2 FROM Table World 3 WHERE Condition Apply OR logic filter 4 Return Results Countries matching either SQL Query: SELECT name, population, area FROM World WHERE area >= 3000000 OR population >= 25000000 FINAL RESULT name population area China 1,400M 9.6M USA 331M 9.8M Russia 144M 17.1M India 1,380M 3.3M Vatican (excluded) Result Summary 4 big countries found Status: OK Why they qualify: China: Both criteria USA: Both criteria Russia: Area only India: Both criteria Key Insight: The OR operator in SQL allows matching rows that satisfy EITHER condition. A country qualifies as "big" if it meets at least one criterion. This is more inclusive than AND (which requires both conditions). Time Complexity: O(n) where n = number of rows. No index needed for simple table scan. TutorialsPoint - Big Countries | Optimal Solution (SQL WHERE with OR clause)
Asked in
Amazon 28 Google 22 Facebook 15
125.0K Views
High Frequency
~8 min Avg. Time
1.9K 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