Skip to content
playdsa
Preferences

Make yourself comfortable.

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

Theme
Advanced settings

Boss fightThe Median Partition

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 Median Partition.

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

How you win

  1. 1Recognize when Binary search on a partition matches the clues
  2. 2Keep this true after every move: the two cuts place the required number of values on the combined left side
  3. 3Reach the result within O(log min(m, n))

Rules and pressure

  • Target cost: O(log min(m, n))
  • State rule: the two cuts place the required number of values on the combined left side

New words in this mission

Open a term for a plain-language explanation.
partition or shard+

One slice of a larger dataset or workload. Splitting work raises capacity, but cross-slice operations become harder.

Lesson 1 of 3

Live algorithm trace

Binary search on a partition

Complete execution
1 of 9

Search cut positions only in the smaller three-value array A.

1binary search the smaller array
2cutA = midpoint
3cutB = half - cutA
4read four partition borders
5if leftA > rightB: move cutA left
6if leftB > rightA: move cutA right
7otherwise compute median
A = [1,3,8]B = [7,9,10,11]half = 4
Truth to preserve / Cost target
Truth to preserve

the two cuts place the required number of values on the combined left side

Cost target

O(log min(m, n))

Partition the smaller array and derive the matching cut in the larger one so the left side holds half the values. A valid partition has both left maxima no greater than both right minima.

Your call · What should guide every step of this algorithm?

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