Complete the code to start the binary search with the correct initial left index.
int left = [1];The binary search starts from the first index, which is 0.
Complete the code to calculate the middle index correctly.
int mid = left + ([1] - left) / 2;
We calculate mid as the average of left and right to avoid overflow.
Fix the error in the condition to check if mid is a peak element.
if ((mid == 0 || nums[mid] > nums[mid - 1]) && (mid == nums.length - 1 || nums[mid] > [1])) { return mid; }
We compare nums[mid] with nums[mid + 1] to check the right neighbor.
Fill both blanks to update the search range correctly when the right neighbor is greater.
if (nums[mid] < nums[[1]]) { [2] = mid + 1; } else { right = mid; }
If the right neighbor is greater, move left pointer to mid + 1 to search right side.
Fill all three blanks to complete the binary search method to find a peak element.
public int findPeakElement(int[] nums) {
int left = [1], right = nums.length - 1;
while (left < right) {
int mid = left + (right - left) / 2;
if (nums[mid] < nums[[2]]) {
left = mid + 1;
} else {
right = [3];
}
}
return left;
}Initialize left to 0. Compare nums[mid] with nums[mid + 1]. Update right to mid when left side is greater or equal.
