Heater and Houses

You are given positions of houses and heaters on a horizontal line, find out the minimum radius of heaters so that all houses could be covered by those heaters.

So, your input will be the positions of houses and heaters separately, and your expected output will be the minimum radius standard of heaters.

NOTE:

  • As long as a house is in the heaters’ warm radius range, it can be warmed.
  • All the heaters follow your radius standard and the warm radius will the same.
  • If there is no heater, return INT_MAX.

Input Format:

First argument will be a 1D array, A, denoting the positions of houses.
Second argument will be a 1D array, B, denoting the positions of heaters.

Output Format

Return an integer that represents the minimum radius.

Constraints:

0 <= A.size(), B.size() <= 25000
0 <= A[i], B[i] <= 10^9

Example 1:

Input: 
    A: [1,2,3]
    B: [2]
    
Output: 
    1
    
Explanation: 
    The only heater was placed in position 2, and if we use the radius 1 standard, then all the houses can be warmed.

Example 2:

Input: 
    A: [1,2,3,4]
    B: [1,4]
    
Output: 
    1
    
Explanation: 
    The two heater was placed in positions 1 and 4. We need to use the radius 1 standard, then all the houses can be warmed.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Heater and Houses on Interview Code Editor
Sign Up
to access hints and editorial solutions for Heater and Houses

Discussion


Loading...
Click here to start solving coding interview questions