All problems
0259MediumArrayGreedySortingHeap (Priority Queue)

Most Inspections Booked

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1353Maximum Number of Events That Can Be Attended

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 safety office has one inspector and a list of sites waiting to be inspected. Entry windows[i] = [opens, closes] means site i may be inspected on any single whole day from day opens to day closes inclusive.

The inspector carries out at most one inspection per day and needs the whole day for it. A site is either inspected on one day inside its window or not inspected at all, and days may be left empty.

Return the largest number of sites the inspector can get through.

Examples

Example 1

Input
windows = [[1, 2], [1, 1]]
Output
2

The second site is inspected on day 1, its only day, and the first site on day 2, which is inside its window of days 1 to 2.

Example 2

Input
windows = [[1, 3], [1, 3], [1, 3]]
Output
3

All three windows span days 1 to 3, so the inspector takes one site on each of those days.

Example 3

Input
windows = [[1, 1], [1, 1], [2, 2]]
Output
2

Day 1 takes one of the two sites whose window is that single day, and day 2 takes the third site. The remaining site has no day left inside its window.

Constraints

  • 1 <= windows.length <= 10^5
  • windows[i].length == 2
  • 1 <= windows[i][0] <= windows[i][1] <= 10^5

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 most_inspections(windows: list[list[int]]) -> int:
Java
public int mostInspections(int[][] windows)
September 7
Apply