Back to course home
0% completed
Maximum Population Year (easy)
Problem Statement
You are given a 2D integer array logs
containing the birth and death years of n
people. In logs
array, logs[i] = [birth<sub>i</sub>, death<sub>i</sub>] indicates the birth and death years of the i<sup>th</sup> person.
The population of a year is the number of people alive during that year. The i<sup>th</sup> person is counted in year x's population if x is in the inclusive range [birth<sub>i</sub>, death<sub>i</sub> - 1].
Return the earliest year with the highest population.
Examples
Example 1:
- Input: logs = [[1980, 1990], [1975, 1985], [1985, 1995], [1990, 2000], [1999, 2020], [1994, 2032]]
- Expected Output:
1994
- Explanation: The population in the year 1994 was the highest. In that year,
3
people were alive (born in 1985, 1990, and 1994).
Example 2:
- Input: logs = [[1970, 1990], [1980, 2009], [1960, 1970], [1959, 1982]]
- Expected Output:
1980
- Explanation: The population in the year 1980 was the highest. In that year, three people were alive (born in 1970, 1980, and 1959).
Example 3:
- Input: logs = [[2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025]]
- Expected Output:
2005
- Explanation: The population in the year 2005 was the highest. In that year, two people were alive (born in 2000, and 2005).
Constraints:
- 1 <= logs.length <= 100
- 1950 <= birth<sub>i</sub> < death<sub>i</sub> <= 2050
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
Mark as Completed
Table of Contents
Problem Statement
Examples
Try it yourself