Complete the code to start the binary search loop.
int left = 0, right = nums.size() - 1; while ([1] <= right) { int mid = left + (right - left) / 2;
The binary search continues while the left index is less than or equal to the right index.
Complete the code to check if the middle element is the target.
if (nums[[1]] == target) { return mid; }
We compare the middle element nums[mid] with the target to check for a match.
Fix the error in the condition to check if the left half is sorted.
if (nums[left] <= nums[[1]]) { // Left half is sorted }
We compare nums[left] with nums[mid] to check if the left half is sorted.
Fill both blanks to update the search boundaries correctly when the left half is sorted.
if (target >= nums[left] && target < nums[mid]) { right = [1]; } else { left = [2]; }
If the target is in the left sorted half, move right to mid - 1; otherwise, move left to mid + 1.
Fill all three blanks to update the search boundaries when the right half is sorted.
else { if (target > nums[mid] && target <= nums[[1]]) { left = [2]; } else { right = [3]; } }
If the target is in the right sorted half, move left to mid + 1; otherwise, move right to mid - 1.