Round 1
Questions:
You are given a mountain array, which is an array that increases and then decreases. Your task is to find the index of the peak element (the element that is greater than both its neighbors).
Input: arr = [11, 12, 15, 16, 17, 32, 10, 2, -33]
Output: 5
Explanation: Peak element is 32 at index 5.
Candidate's Approach
- Binary Search:
Since the array first increases and then decreases, we can use binary search to find the peak efficiently in O(log n) time.- If the element at mid is less than the next element (arr[mid] < arr[mid + 1]), move to the right part of the array.
- Otherwise, move to the left part.
- The loop continues until start == end, at which point start will be the peak index.
Interviewer's Feedback
No feedback provided.