The median of five numbers in six comparisons
You have five distinct numbers, a, b, c, d and e, hidden in sealed envelopes. The only operation allowed is to compare two of them and learn which is larger.
Find the median (the third largest) using at most six comparisons. Sorting all five would take seven; show how to save one, and explain why five comparisons can never be enough.
Show a hint
Compare a with b and c with d. Then compare the two smaller ones. The smaller of those is below three numbers and cannot be the median. Now the median is the second smallest of the four survivors.
Your answer
Solving needs a free account
Answers, streaks and solutions unlock when you are signed in. Reading the question and the hint stays free.
Discussion
Sign in to join the discussion · reading is open to everyone
💡 Discussion rules
- No full solutions here. Hints and approaches only.
- Complexity, edge cases and intuition are the point.
- Interview experiences are welcome. Respect your NDAs.
Loading discussion…
Learn the concepts
The theory behind this question.
Related questions
Sort four items in five comparisonsThe heaviest and the runner-up among eight coinsBoth the lightest and the heaviest of ten coinsFinding one honest agent among liarsFind the duplicated number
All questions →