pop
of size 101 (since the years range from 1950 to 2050) to store the net population changes.logs
and for each log:
a. Increment pop[birth year - 1950]
by 1.
b. Decrement pop[death year - 1950]
by 1.max_population
to 0 and max_year
to 1950.pop
array and for each index:
a. Update pop[i]
with pop[i] + pop[i - 1]
to get the current population.
b. If pop[i]
is greater than max_population
, update max_population
and set max_year
to i + 1950
.max_year
as the earliest year with the maximum population.