Fewest Cell Towers to Cover Every Village Along a Highway
Last updated: November 29, 2026
Quick Overview
Villages sit at integer mile markers along a straight highway, and each tower placed at position p covers every village within distance r. Return the minimum number of towers needed to cover all villages.
0
0
0 solved
Villages sit at integer mile markers along a straight highway, and each tower placed at position p covers every village within distance r. Return the minimum number of towers needed to cover all villages.
Coverage placement is a good fit for Google Fi and network planning conversations. The interviewer is checking that you place each tower as far right as possible while still covering the leftmost uncovered village, and that you can prove it.
What the Interviewer Expects
- Sort village positions
- Place each tower at leftmost uncovered village plus r
- Skip every village the tower covers
- Give the exchange argument
- O(n log n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Towers can only be built at allowed sites. Adapt the greedy.
- Each village has a different required radius.
- Towers cost different amounts at different sites.
- Villages are on a 2D plane. Why is that NP-hard and what would you do?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of village positions (ints, may repeat) and radius r >= 0. A tower at p covers village x when |x - p| <= r. Towers can be placed anywhere. Output: minimum tower count....
High-Level Design
Sort positions. Take the leftmost uncovered village x. Some tower must cover it, so it sits in [x - r, x + r]. Placing it at x + r covers x and reaches as far right as possible, and there are ...