Heaters

Problem Id: 475 Difficulty: Medium


Intuition

Solution


class Solution:
    def findRadius(self, houses: List[int], heaters: List[int]) -> int:
        j = 0
        radius = 0
        houses.sort()
        heaters.sort()

        for house in houses:
            while j < len(heaters) - 1 and (abs(heaters[j] - house) >= abs(heaters[j+1] - house)):
                j += 1
            radius = max(radius, abs(heaters[j] - house))
        return radius