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.

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

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
Two Pointers
Greedy
Proof of Correctness
Arrays
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
  • 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 Problems
Sample Answer
Requirements
  • Input: list heights of non-negative integers, at least two masts.
  • Area for masts i < j is (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 ...


Submit Your Answer
Markdown supported