Problem context and objectives
Mission briefing
Signal rescue operator · A beacon is hidden inside an ordered frequency band
Lock onto the signal without testing every frequency: The First Signal.
Each probe costs precious time; searching the wrong half moves the rescue team farther away.
How you win
- 1Recognize when Binary-search boundary matches the clues
- 2Keep this true after every move: no discarded index can be the first target
- 3Reach the result within O(log n)
Rules and pressure
- Target cost: O(log n)
- State rule: no discarded index can be the first target
New words in this mission
Open a term for a plain-language explanation.O(log n)+
The work grows by one step when the input roughly doubles. Binary search achieves this by discarding half of the remaining search space each time.
Lesson 1 of 3
Live algorithm trace
Binary-search boundary
Complete execution1 of 5
The first target may be anywhere in the full sorted range.
1
left, right = 0, len(nums)-12
mid = (left+right)//23
if nums[mid] >= target: right = mid-14
return answertarget = 2left = 0right = 4answer = -1
Truth to preserve / Cost target
Truth to preserve
no discarded index can be the first target
Cost target
O(log n)
Binary search can find more than an exact value. When a match appears, keep searching left to prove whether an earlier match exists.
Your call · What should guide every step of this algorithm?