Ctrl K

The Busiest Year

Easy
An archive keeps records about the residents of a small village. Each entry of lifespans is a pair [birth, death]: the year a person was born and the year they died. A person counts as alive in year x when birth ≤ x < death. They are no longer counted in the year of their death. Find the year in which the most people were alive at the same time. If several years tie, return the earliest one.
Example 1
lifespans=[[1960, 1975], [1970, 1990], [1985, 2000]] → 1970

From 1970 through 1974 two people are alive at once, the first and the second. Two are also alive in 1985–1989, but 1970 is the earliest year with that count.

Example 2
lifespans=[[2001, 2010], [2010, 2020]] → 2001

The first person no longer counts in 2010, so no more than one person is ever alive at a time and the answer is the earliest year, 2001.

Example 3
lifespans=[[1990, 2000], [1995, 2005], [1998, 2003], [1950, 2050]] → 1998
Constraints
  • 1 ≤ len(lifespans) ≤ 100
  • 1950 ≤ birth < death ≤ 2050
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBalanced Cuts After One Replacement HardMatching Ends per Range MediumPump Rods at Their Peak HardPair GCDs by Sorted Position HardThe Candidate With Most Votes Easy
loading Python…
Input
lifespans=[[1960, 1975], [1970, 1990], [1985, 2000]]
Expected
1970

Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.