Maximum Population Year
Real-world version: Busiest Lease YearThe statement here is our own: the same inputs, outputs and technique.
A market hall keeps one record per shop lease. Entry logs[i] = [start_i, end_i] means that lease occupied a unit from the start of year start_i and was handed back at the start of year end_i, so it counts as active in every year from start_i up to and including end_i - 1, and not in end_i itself.
A year's occupancy is the number of leases active in that year. Return the earliest year whose occupancy is as large as any year's occupancy. If several years share the largest occupancy, return the smallest of them.
Examples
Example 1
- Input
- logs = [[1972, 1986], [1968, 1978], [1980, 1992]]
- Output
- 1972
In 1972 the first lease has just begun and the second is still running, so the occupancy is 2. No year here reaches 3, and 1972 is the first year that reaches 2.
Example 2
- Input
- logs = [[1970, 1980], [1990, 2000]]
- Output
- 1970
The two leases never overlap, so no year has occupancy above 1. Both 1970 and 1990 have occupancy 1, and the smaller of the tied years is returned.
Example 3
- Input
- logs = [[2049, 2050]]
- Output
- 2049
The single lease is active in 2049 only, because a lease does not count in its end year.
Constraints
- 1 <= logs.length <= 100
- logs[i].length == 2
- 1950 <= start_i < end_i <= 2050
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def maximum_population(logs: list[list[int]]) -> int:public int maximumPopulation(int[][] logs)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's