Domain 1EasyCORE

Big Countries

The problem asks us to identify "big countries" from a given table named `World`. A country is considered "big" if it has either a large population or a large area. Specifically: - The table `World` contains the following columns: `name`, `continent`, `area`, and `population`. - We need to return the names of countries that have an area greater than 3 million square kilometers or a population greater than 25 million.

Domain: Easy•Updated: 2026-08-31
#Algorithms#LeetCode#qwen2.5-coder:14b#**FAANG asked:** 0

595. Big Countries

Model: qwen2.5-coder:14b
Topics:
FAANG asked: 0
Acceptance rate: 78.7%


Problem Breakdown

The problem asks us to identify “big countries” from a given table named World. A country is considered “big” if it has either a large population or a large area. Specifically:

  • The table World contains the following columns: name, continent, area, and population.
  • We need to return the names of countries that have an area greater than 3 million square kilometers or a population greater than 25 million.

Inputs:

  • A table World with columns name, continent, area, and population.

Outputs:

  • A list of country names that meet the criteria of being “big”.

Implicit Constraints/Edge Cases:

  • The table might be empty.
  • There could be duplicate entries for countries, though this is not explicitly stated in the problem description.
  • The area and population values are non-negative integers.

Intuition

To solve this problem, we need to filter rows from the World table based on two conditions:

  1. The country’s area must be greater than 3 million square kilometers.
  2. The country’s population must be greater than 25 million.

A brute-force approach would involve iterating through each row of the table and checking both conditions for each row. This approach is straightforward but inefficient, especially if the table contains a large number of rows, as it has a time complexity of O(n).

The key insight to improve this solution is to leverage SQL’s filtering capabilities directly in the query. By using the WHERE clause with logical OR, we can efficiently filter out countries that do not meet either condition.

Approach

  1. Select the required column: We need to select only the name column from the World table.
  2. Apply the conditions: Use the WHERE clause to apply the two conditions:
    • area > 3000000
    • population > 25000000
  3. Combine conditions with OR: Since a country is considered “big” if it meets either condition, we use the logical OR operator (OR) to combine these conditions.

Complexity Analysis

  • Time Complexity: O(n), where n is the number of rows in the World table. This is because we need to examine each row once to apply the filtering conditions.
  • Space Complexity: O(1) for the query itself, as it does not require additional space that grows with input size.

Solution

SELECT name 
FROM World 
WHERE area > 3000000 OR population > 25000000;

Edge Cases Handled

  • Empty Table: If the World table is empty, the query will return an empty result set.
  • Duplicate Entries: The query does not explicitly handle duplicates. If there are duplicate entries for a country, all such entries will be included in the result if they meet the criteria. Depending on the requirements, additional logic might be needed to handle duplicates.

This solution is efficient and leverages SQL’s capabilities to filter data directly, making it suitable for large datasets.