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.