The Heaters interview question is an optimization problem involving two sets of coordinates: houses and heaters. You need to find the minimum possible "radius" for the heaters such that every house is covered by at least one heater. All heaters will have the same radius. A house at position is covered by a heater at position if the distance is less than or equal to the radius.
Companies like Google, Amazon, and Microsoft ask this to evaluate a candidate's ability to search through large coordinate spaces efficiently. It tests your knowledge of Binary Search interview patterns and Two Pointers interview patterns. The problem can be solved in multiple ways, allowing the interviewer to see how you weigh different time-space trade-offs. It also requires careful handling of sorted vs. unsorted input data.
There are three main ways to approach the Heaters coding problem:
Houses: [1, 5], Heaters: [2]
When you need to find the "closest" element in a collection for many queries, sorting and binary search are your best friends. Practice the bisect module in Python or Arrays.binarySearch in Java to efficiently find "insertion points" in sorted data.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Number of Subsequences That Satisfy the Given Sum Condition | Medium | Solve | |
| 3Sum Smaller | Medium | Solve | |
| Count the Number of Fair Pairs | Medium | Solve | |
| Successful Pairs of Spells and Potions | Medium | Solve | |
| Friends Of Appropriate Ages | Medium | Solve |