Trains the technique from
LeetCode 475HeatersThis 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 pipeline runs dead straight. sensors gives the positions of the sensor nodes
bolted along it and masts gives the positions of the relay masts. Positions are
whole numbers of metres, they arrive in no particular order, and two entries may
share a position.
Every mast is configured with the same reach r. A mast at position p then
covers the stretch from p - r to p + r, endpoints included, and a sensor
counts as covered when at least one mast reaches it.
Return the smallest reach r that leaves every sensor covered.
Example 1
The single mast sits at 5, so the three sensors are 2, 3 and 4 metres away. A reach of 4 covers all three.
Example 2
The sensor at 3 is 2 metres from the mast at 1, the sensor at 8 is 2 metres from the mast at 10, and the sensor at 12 is also 2 metres from the mast at 10.
Example 3
The sensor at 9 is 7 metres from the mast at 2 and 91 metres from the mast at 100, so a reach of 7 covers it.
Example 4
Every sensor shares a position with a mast, so no reach at all is needed.
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 find_radius(sensors: list[int], masts: list[int]) -> int:public int findRadius(int[] sensors, int[] masts)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.