Choose Two Antenna Masts That Enclose the Widest Coverage Area
Last updated: November 29, 2026
Quick Overview
Masts stand at equal spacing along a road with given heights. Pick two masts so that the rectangle between them, as tall as the shorter mast, has the largest area, and return that area.
0
0
0 solved
Masts stand at equal spacing along a road with given heights. Pick two masts so that the rectangle between them, as tall as the shorter mast, has the largest area, and return that area.
A Google phone-screen classic dressed up as a coverage planning problem. The interviewer wants the O(n) two-pointer solution and, more importantly, a clear argument for why moving the shorter mast is always safe.
What the Interviewer Expects
- Starts with the widest pair
- Always moves the pointer at the shorter mast
- Gives a correct exchange argument for discarding the shorter side
- Handles equal heights
- States O(n) time and O(1) space
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
- What if masts are at arbitrary positions rather than equal spacing?
- How would you return the indices of the best pair?
- What if you can pick three masts and the area is between the outer two at the height of the shortest?
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
heightsof non-negative integers, at least two masts. - Area for masts
i < jis(j - i) * min(heights[i], heights[j]). - Output: the maximum area....
High-Level Design
Start with lo = 0, hi = n - 1, the widest pair. Record the area. Then move the pointer at the shorter mast inward. Argument: suppose heights[lo] <= heights[hi]. Any pair (lo, j) with j < hi ...