The Count Covered Buildings interview question (likely a variation of an interval coverage problem) asks you to determine how many buildings are "covered" or "hidden" based on their heights and positions. Usually, a building is considered covered if there is a taller building to its left or right within a certain range, or if it falls within the "shadow" of another building.
Amazon uses this Array interview pattern to test your ability to work with sorted data and intervals. It evaluates if you can use a "Sweep Line" algorithm or a Monotonic Stack to efficiently process linear data. It’s a "Medium" problem that requires identifying which buildings are redundant in a visibility or coverage set.
This problem is typically solved using Sorting and a Greedy approach or a Sweep Line.
max_reach or max_height seen so far.max_reach of a previous taller building.Buildings: (pos: 1, height: 10), (pos: 2, height: 5), (pos: 5, height: 12)
max_height = 10.max_height (10) and it's to the right, it might be considered "covered."12 > 10, so this building is NOT covered and becomes the new max_height.Whenever you see a problem involving "covering," "shadowing," or "merging," your first thought should be to Sort the input. Sorting by position or height usually simplifies the problem into a single-pass scan.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Index of a Valid Split | Medium | Solve | |
| Analyze User Website Visit Pattern | Medium | Solve | |
| Arithmetic Subarrays | Medium | Solve | |
| Largest Unique Number | Easy | Solve | |
| Minimum Swaps to Sort by Digit Sum | Medium | Solve |