Complete the code to initialize the binary search boundaries for the answer.
low, high := 0, [1]
We set high to a large number as the upper bound for the answer search space.
Complete the code to calculate the middle value in binary search safely.
mid := low + (high - [1]) / 2
We subtract low from high to avoid overflow, then add low back.
Fix the error in the condition to check if mid is a valid answer.
if canAchieve(arr, [1]) {
We check if the current middle value mid can achieve the goal.
Fill both blanks to update the binary search boundaries correctly.
if canAchieve(arr, mid) { high = [1] } else { low = [2] }
If mid works, we try smaller or equal values by setting high = mid. Otherwise, we try larger values by setting low = mid + 1.
Fill all three blanks to return the final answer after binary search.
for low < high { mid := low + (high - low) / 2 if canAchieve(arr, mid) { high = [1] } else { low = [2] } } return [3]
Inside the loop, update high to mid if condition is true, else update low to mid + 1. After the loop, low holds the smallest valid answer.