All problems
0138MediumArrayDynamic ProgrammingGreedySorting

Drop the Clashing Kiln Runs

Tracked in this browser only
Write code

Trains the technique from

LeetCode 435Non-overlapping Intervals

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 ceramics studio books firings on one shared kiln. Every request comes in as a pair [start, finish] inside runs, both measured in minutes from the studio's reference mark; a request that sits earlier than the mark uses negative minutes, and a firing always finishes after it starts.

Two requests clash when the stretches of kiln time they occupy share at least one minute. A firing that finishes on the exact minute another begins does not clash with it, since the kiln is free again at that mark.

Cancel as few requests as possible so that no two survivors clash. Return how many requests you had to cancel.

Examples

Example 1

Input
runs = [[1, 4], [2, 6], [5, 9]]
Output
1

Cancelling the request that runs from 2 to 6 leaves the other two, which share no minute. Keeping all three is impossible because the middle firing clashes with both of the others.

Example 2

Input
runs = [[-3, 0], [0, 5], [5, 8]]
Output
0

Each firing finishes exactly when the next one begins, so the kiln is never double booked and nothing has to go.

Example 3

Input
runs = [[0, 10], [9, 12], [11, 20]]
Output
1

Dropping the short middle request keeps the two long firings, which never overlap. Cancelling one of the long firings instead would leave the remaining pair still clashing.

Constraints

  • 1 <= runs.length <= 10^5
  • runs[i].length == 2
  • -5 * 10^4 <= start < finish <= 5 * 10^4
  • Requests that only touch at a single minute mark do not clash

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 min_runs_to_cancel(runs: list[list[int]]) -> int:
Java
public int minRunsToCancel(int[][] runs)
September 7
Apply