Complete the code to initialize the binary search boundaries.
let low = 0; let high = [1];
We set high to arr.length - 1 because array indices go from 0 to length minus one.
Complete the code to calculate the middle index safely.
let mid = low + Math.floor([1] / 2);
We calculate mid as low + Math.floor((high - low) / 2) to avoid overflow and find the middle index.
Fix the error in the condition to move the low pointer.
if (canAchieve(mid)) { low = [1]; } else { high = mid - 1; }
When canAchieve(mid) is true, we move low to mid + 1 to search higher values.
Fill both blanks to complete the binary search loop condition and update.
while ([1] <= [2]) { let mid = low + Math.floor((high - low) / 2); if (canAchieve(mid)) { low = mid + 1; } else { high = mid - 1; } }
The loop runs while low <= high to cover all possible values in the search range.
Fill all three blanks to return the correct final answer after binary search.
return [1] - 1; // where [2] is the last successful mid // and [3] is the variable updated when canAchieve(mid) is true
After the loop, low is one more than the last successful mid, so we return low - 1.
