Binary Search Quiz
Editorial
13 questions across the four Binary Search lessons: what a task should search, which update keeps the answer, which question flips once, and what a small bug does. Pick an answer to see whether it's right and why. Nothing is saved, so you can take it again.
If one trips you up, its lesson is Introduction to Binary Search, Binary Search Without a Sorted Array, Binary Search on the Answer or Binary Search on Two Sorted Arrays and Matrices.
Quiz
1 / 13Multiple choice
Find the smallest ship capacity that ships every package within D days. What do you binary search?
Multiple choice
Find the median of two sorted arrays in O(log min(m, n)). What do you binary search?
Multiple choice
Is 14 in a matrix whose rows are sorted and whose columns are sorted, when a row can start below where the row above ends? What do you binary search?
Multiple choice
Find where a value would be inserted to keep a sorted array sorted. What do you binary search?
Multiple choice
The first-yes loop has lo = 2 and hi = 6, and at mid = 4 the answer is yes. What's the update?
Multiple choice
In the last-yes loop, a yes sets lo = mid. Why must mid round up there?
Multiple choice
Along the rotated array [4, 5, 6, 7, 0, 1, 2], which question flips only once?
Multiple choice
Capacity To Ship Packages Within D Days: as the capacity c grows, which question can be binary searched?
Multiple choice
Search a 2D Matrix on a 5 × 8 grid read row by row. Which cell is position 21?
Multiple choice
Kth Element of Two Sorted Arrays: a = [1, 4, 9], b = [2, 3, 5, 8], k = 5. The loop tries 2 from a and 3 from b; b's last taken value is 5 and a's first value left out is 9. What does it do?
Multiple choice
A value search uses
while lo < hi, with lo = mid + 1 and hi = mid - 1, and returns -1 after the loop. What does it return for 3 in [1, 3]?Multiple choice
In Java, lo and hi can both be near 2 × 10^9. Which mid is safe?
Multiple choice
Search in Rotated Sorted Array II: nums[lo], nums[mid] and nums[hi] are all 1, and the target isn't 1. What can you safely do?