2485. Finding the Number of Visible Mountains

Medium
Array
Stack
Sorting
Monotonic Stack

Description

Hints

Hint 1
How can we efficiently find for each mountain the relevant mountains to compare itself against to check whether or not it would be visible?
Hint 2
Do you notice a pattern after sorting the peaks by their x-coordinates?
Hint 3
After sorting, process the peaks sequentially and use a monotonic stack to store currently visible mountains.

Statistics

Acceptance
37.1%
Submissions
34,032
Accepted
12,609