Grokking the Coding Interview: Patterns for Coding Questions

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:

.....

.....

.....

Like the course? Get enrolled and start learning!