Finding Large Nations
Many applications require filtering data based on specific criteria. A common task is identifying entities that exceed a certain threshold. This challenge involves identifying countries with a population larger than a specified number and an area greater than another specified number.
Problem Description
You are given a dataset of countries, where each country has a name, population, and area. Your task is to write a program that returns the names of all countries that satisfy two conditions simultaneously:
- Population Threshold: The country's population must be greater than a given minimum population.
- Area Threshold: The country's area must be greater than a given minimum area.
The program should output a list of the names of these qualifying countries.
Examples
Example 1:
Input:
Countries:
[
{ name: "China", population: 1444216107, area: 9596961 },
{ name: "India", population: 1393409038, area: 3287590 },
{ name: "United States", population: 332915073, area: 9833520 },
{ name: "Indonesia", population: 276361783, area: 1904569 },
{ name: "Pakistan", population: 225199937, area: 770880 }
]
Minimum Population: 100000000
Minimum Area: 5000000
Output:
[ "China", "United States" ]
Explanation:
- China has a population of 1444216107 (greater than 100000000) and an area of 9596961 (greater than 5000000).
- India has a population of 1393409038 (greater than 100000000) but an area of 3287590 (not greater than 5000000).
- United States has a population of 332915073 (greater than 100000000) and an area of 9833520 (greater than 5000000).
- Indonesia has a population of 276361783 (greater than 100000000) but an area of 1904569 (not greater than 5000000).
- Pakistan has a population of 225199937 (greater than 100000000) but an area of 770880 (not greater than 5000000).
Only China and United States meet both criteria.
Example 2:
Input:
Countries:
[
{ name: "Brazil", population: 213993437, area: 8515767 },
{ name: "Nigeria", population: 211400708, area: 923768 },
{ name: "Bangladesh", population: 166303498, area: 147570 }
]
Minimum Population: 200000000
Minimum Area: 1000000
Output:
[ "Brazil" ]
Explanation:
- Brazil has a population of 213993437 (greater than 200000000) and an area of 8515767 (greater than 1000000).
- Nigeria has a population of 211400708 (greater than 200000000) but an area of 923768 (not greater than 1000000).
- Bangladesh has a population of 166303498 (not greater than 200000000).
Only Brazil meets both criteria.
Example 3: (Edge Case: No countries meet the criteria)
Input:
Countries:
[
{ name: "Canada", population: 38246108, area: 9984670 },
{ name: "Australia", population: 25921093, area: 7692024 }
]
Minimum Population: 100000000
Minimum Area: 10000000
Output:
[]
Explanation:
Neither Canada nor Australia meet both the population and area thresholds.
Constraints
- The number of countries in the dataset will be between 0 and 1000.
- Each country's
namewill be a non-empty string. - Each country's
populationwill be a non-negative integer. - Each country's
areawill be a non-negative integer. Minimum PopulationandMinimum Areawill be non-negative integers.- The solution should be efficient enough to process up to 1000 countries within a reasonable time frame (e.g., under 1 second).
Notes
- You will need to iterate through the list of countries.
- For each country, you will perform two comparisons.
- Consider how to store and return the names of the qualifying countries.
- The order of the output list does not matter.