Trains the technique from
LeetCode 56Merge IntervalsThis 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 leak-detection crew has bolted acoustic sensors along a straight water pipeline. You are handed segments, where segments[i] = [start_i, end_i] records the stretch of pipe that sensor i can hear, measured in metres from the pumping station. A sensor whose two numbers are equal listens at a single point on the pipe.
Two stretches sit inside one monitored region whenever they share at least one point of pipe, and that includes the case where one stretch stops exactly where another picks up. Stretches that merely sit close together, with a gap of pipe between them however small, stay separate. Collapse the sensor list down to the fewest monitored regions that still cover precisely the same pipe, then return those regions arranged from the lowest starting metre to the highest.
The crew records sensors in whatever order the technicians walked the line, so segments arrives unordered.
Example 1
The stretch 3..7 and the stretch 6..9 both hear metre 6, so they fold into 3..9. Nothing touches 12..18, and the point sensor at metre 25 stands on its own.
Example 2
One stretch ends at metre 45 and the next begins there, so the shared mark joins them into a single region.
Example 3
The shorter stretch sits wholly inside the longer one, which leaves the wider region unchanged.
Example 4
Two point sensors with no metre mark in common stay separate, even though only three metres of pipe divide them.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def merge_coverage(segments: list[list[int]]) -> list[list[int]]:public int[][] mergeCoverage(int[][] segments)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.