2345. Finding the Number of Visible Mountains
ArrayStackSortingMonotonic Stack
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.
Preparing judge…