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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

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
Greedy
Sorting
Coverage
Exchange argument
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported