Skip to content

Latest commit

 

History

History
47 lines (34 loc) · 1.26 KB

_475. Heaters.md

File metadata and controls

47 lines (34 loc) · 1.26 KB

475. Heaters

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 07, 2024

Last updated : July 01, 2024


Related Topics : Array, Two Pointers, Binary Search, Sorting

Acceptance Rate : 39.01 %


Solutions

Python

# Only issue encountered was I assumed that the arrays were sorted :l

class Solution:
    def findRadius(self, houses: List[int], heaters: List[int]) -> int:
        maxx = 0
        heaters.sort()
        for house in houses :
            indx = bisect_left(heaters, house)

            if indx == len(heaters): 
                maxx = max(maxx, abs(heaters[indx - 1] - house))
            elif heaters[indx] == house :
                continue
            elif indx == 0 :
                maxx = max(maxx, abs(heaters[indx] - house))
            else :
                maxx = max(maxx, min(abs(heaters[indx] - house), abs(heaters[indx - 1] - house)))

        return maxx