Medium
Quiz
#475 Heaters
APPROACH
Houses and heaters are placed at integer positions on a number line. Every heater has the same radius, and a house is covered when it lies within that radius of any heater. Given arrays houses and heaters, return the smallest radius that guarantees all houses are covered.
Example 1:
Input: houses = [1,2,3], heaters = [2]
Output: 1
Explanation: The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.
Example 2:
Input: houses = [1,2,3,4], heaters = [1,4]
Output: 1
Explanation: The two heaters were placed at positions 1 and 4. We need to use a radius 1 standard, then all the houses can be warmed.
Example 3:
Input: houses = [1,5], heaters = [2]
Output: 3
1 of 4
1:00
What is the optimal approach for this problem?