The Find the Peaks interview question is an introductory array traversal task. You are given an array of integers representing heights (mountain ranges). A "peak" is an element that is strictly greater than its immediate left neighbor and its immediate right neighbor. Your goal is to return a list containing the indices of all such peaks. Note that elements at the very beginning and end of the array cannot be peaks because they lack two neighbors.
Companies like Meta ask the Find the Peaks coding problem as a warm-up to verify basic programming skills. It tests your ability to handle array indexing safely, implement conditional logic, and manage boundaries. It evaluations your proficiency in Enumeration and simple linear scans within an Array interview pattern.
This problem uses a simple Linear Scan (One-pass) pattern.
mountain[i] > mountain[i-1] AND mountain[i] > mountain[i+1].mountain = [0, 1, 4, 2, 5, 3]
[2, 4].IndexOutOfBoundsException when checking neighbors.>= instead of >, failing to handle the "strictly greater" requirement.Always check the "neighborhood" constraints in array problems. If a definition depends on and , your loop range should be restricted to [1, n-2]. This is a fundamental safe-coding practice in Array interview patterns.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count Good Triplets | Easy | Solve | |
| Detect Pattern of Length M Repeated K or More Times | Easy | Solve | |
| Maximum Height of a Triangle | Easy | Solve | |
| Collecting Chocolates | Medium | Solve | |
| Coordinate With Maximum Network Quality | Medium | Solve |