LeetCode 475 Heaters

LeetCode 475 Heaters Problem

Download Code
class Solution(object):
    def findRadius(self, houses, heaters):
        """
        :type houses: List[int]
        :type heaters: List[int]
        :rtype: int
        """
        heaters = sorted(heaters) + [float('inf')]
        i = r = 0
        for x in sorted(houses):
            # move to next range
            while x >= sum(heaters[i:i + 2]) / 2.:
                i += 1
            # ans = hearter - hourse
            r = max(r, abs(heaters[i] - x))
        return r
Download Heaters.py

List of all Heaters problems

Leetcode 475 Heaters problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.