Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
How can we efficiently find for each mountain the relevant mountains to compare itself against to check whether or not it would be visible?
Do you notice a pattern after sorting the peaks by their x-coordinates?
After sorting, process the peaks sequentially and use a monotonic stack to store currently visible mountains.