Question bank › Two Pointers
Dsa Two Pointers Hard

Mountain Range View

You are given an array of integers representing the heights of a series of mountain peaks. Your task is to find how many peaks can be seen from both ends if standing at either end of the array. A peak is visible if there are no taller mountains between it and the observer in either direction. Input format: - The first line contains an integer n (1 ≤ n ≤ 10^5), the number of mountains. - The second line contains n space-separated integers (0 ≤ height_i ≤ 10^6) representing the heights of the mountains. Output format: - Output a single integer, the total number of visible peaks. Example: Input: 6 2 4 3 5 1 6 Output: 4

Key concepts

two_pointersarraysgreedy

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.