All problems
0610EasyArrayCountingPrefix Sum

Busiest Lease Year

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1854Maximum Population Year

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def maximum_population(logs: list[list[int]]) -> int:
Java
public int maximumPopulation(int[][] logs)
September 7
Apply