The Finding the Number of Visible Mountains interview question is a 2D geometry and interval problem. Each mountain is represented by its peak and extends downwards at 45-degree angles to the X-axis. A mountain is "visible" if it is not completely covered by any other mountain. If two mountains are identical, both are considered invisible (or only one is counted, depending on the variant).
Companies like Salesforce and Google ask the Finding the Number of Visible Mountains coding problem to see if a candidate can transform 2D shapes into 1D intervals. It evaluations your ability to use Monotonic Stacks or Sorting to handle overlapping ranges. It’s a test of spatial reasoning and geometric simplification.
This problem follows the Interval Covering pattern.
right_boundary seen so far. A mountain is potentially visible if its end point is greater than the current right_boundary.Mountain 1: peak (2, 2) -> Range [0, 4]. Mountain 2: peak (3, 1) -> Range [2, 4].
max_right = 4.Whenever you see "shapes" that cover other "shapes," try to find a 1D projection. Converting 2D geometry into an Interval interview pattern problem is one of the most effective ways to reduce complexity from to .
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximum Length of Semi-Decreasing Subarrays | Medium | Solve | |
| Car Fleet | Medium | Solve | |
| The Number of Weak Characters in the Game | Medium | Solve | |
| Max Chunks To Make Sorted | Medium | Solve | |
| Max Chunks To Make Sorted II | Hard | Solve |