Recall & Review
beginner
What is a peak element in an array?
A peak element is an element that is greater than its neighbors. For the first or last element, only one neighbor is considered.
Click to reveal answer
intermediate
Why is binary search useful for finding a peak element?
Binary search helps find a peak element in O(log n) time by comparing middle elements with neighbors and deciding which half to search next.
Click to reveal answer
beginner
In the binary search for a peak element, if the middle element is less than its right neighbor, which side do we search next?
We search the right half because a peak must exist there since the right neighbor is greater.
Click to reveal answer
beginner
What is the time complexity of finding a peak element using binary search?
The time complexity is O(log n) because the search space is halved in each step.
Click to reveal answer
beginner
Show the TypeScript function signature for finding a peak element using binary search.
function findPeakElement(nums: number[]): numberClick to reveal answer
What is a peak element in an array?
✗ Incorrect
A peak element is defined as an element greater than its neighbors.
If nums[mid] < nums[mid + 1], which half should we search next to find a peak?
✗ Incorrect
If the middle element is less than its right neighbor, a peak must exist in the right half.
What is the time complexity of the binary search approach to find a peak element?
✗ Incorrect
Binary search reduces the search space by half each time, resulting in O(log n) time.
Which of these is a valid base case for the peak element search?
✗ Incorrect
If the array has one element, that element is the peak by definition.
What does the function findPeakElement return?
✗ Incorrect
The function returns the index of any one peak element found.
Explain how binary search is used to find a peak element in an array.
Think about how the array is divided and how the peak is guaranteed in one half.
You got /4 concepts.
Describe the conditions that determine if the middle element is a peak or which side to search next.
Focus on comparisons between middle element and its neighbors.
You got /3 concepts.