<p>Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses.</p>

<p>Every house can be warmed, as long as the house is within the heater&#39;s warm radius range.&nbsp;</p>

<p>Given the positions of <code>houses</code> and <code>heaters</code> on a horizontal line, return <em>the minimum radius standard of heaters&nbsp;so that those heaters could cover all houses.</em></p>

<p><strong>Notice</strong> that&nbsp;all the <code>heaters</code> follow your radius standard, and the warm radius will the same.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> houses = [1,2,3], heaters = [2]
<strong>Output:</strong> 1
<strong>Explanation:</strong> The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> houses = [1,2,3,4], heaters = [1,4]
<strong>Output:</strong> 1
<strong>Explanation:</strong> 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.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> houses = [1,5], heaters = [2]
<strong>Output:</strong> 3
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= houses.length, heaters.length &lt;= 3 * 10<sup>4</sup></code></li>
	<li><code>1 &lt;= houses[i], heaters[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def findRadius(self, houses: List[int], heaters: List[int]) -> int:

        houses = sorted(houses)
        heaters = sorted(heaters)

        heaters = [float('-inf')] + heaters + [float('inf')]

        sol = 0
        index = 0
        # iterate through houses
        for house in houses:

            # iterate through heaters to get house between heaters
            while house > heaters[index + 1]:

                index += 1

            left_distance = abs(heaters[index] - house)
            right_distance = abs(heaters[index + 1] - house)

            curr_distance = min(left_distance, right_distance)

            sol = max(sol, curr_distance)

        return sol

        # # brute force
        # radius_needed = 0

        # heater, house = 0, 0

        # houses = sorted(set(houses)) # there's a bug in dataset needed to be sorted(set()) in a test case
        # heaters = sorted(set(heaters))

        # # assume more houses than heaters
        # while house < len(houses):
        #     curr_radius = abs(houses[house]-heaters[heater])
        #     # check next heater if available

        #     if heater + 1 < len(heaters) and (abs(houses[house]-heaters[heater+1]) < curr_radius):

        #         heater += 1
        #         # if 1520 <= house <= 1525:
        #         #     print(f'house {house}, heater {heater-1}, curr_radius {curr_radius}, next_radius {abs(houses[house]-heaters[heater])}, radius_needed {radius_needed}')
        #     else:
                
        #         # print(f'at house {house}, heater {heater}, setting radius_needed to max of {curr_radius},{radius_needed}')


        #         radius_needed = max(curr_radius, radius_needed)

        #         house += 1

        # return radius_needed


            
18700