Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Split Peak Signal

Learn
Play
Prove
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 Split Peak Signal.

Each probe costs precious time; searching the wrong half moves the rescue team farther away.

How you win

  1. 1Recognize when Exact binary search matches the clues
  2. 2Keep this true after every move: if the target exists, it remains inside the inclusive interval from left through right
  3. 3Reach the result within O(log n)

Rules and pressure

  • Target cost: O(log n)
  • State rule: if the target exists, it remains inside the inclusive interval from left through right

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

Predict the returned index. For a missing target, watch the boundaries cross. Lesson questions refer to the original example.

Live algorithm trace

Binary search: shrinking candidate interval

Complete execution
1 of 7

Live indices: 0, 1, 2, 3, 4, 5, 6. Short blocks are discarded candidates.

The inclusive interval [0, 6] contains every possible target position.

1left, right = 0, len(nums) - 1
2while left <= right:
3 mid = left + (right - left) // 2
4 if nums[mid] < target: left = mid + 1
5 elif nums[mid] > target: right = mid - 1
6 else: return mid
7return -1
target = 11left = 0right = 6comparisons = 0candidates = 7operation = initialize
Truth to preserve / Cost target
Truth to preserve

If the target exists, its index stays inside [left, right]. Every unsuccessful comparison removes mid and at least half the remaining candidates.

Cost target

O(log(n + 1)) comparisons and O(1) auxiliary space

Use sorted values to prove an entire half impossible. Short blocks show eliminated candidates.

Your call · Target is 11 and mid=3 contains 7. Which indices are now impossible?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead