MindYourPuzzleMindYourPuzzle
Insight · ★★★☆☆ · ~6 min

Min & Max Simultaneously

Find both min and max of n numbers — how few comparisons?

by MindYourPuzzle

Finding the minimum of n numbers takes n-1 comparisons. Finding the maximum takes n-1 comparisons. Finding both naively: 2n-2.

Can you find both in fewer than 2n-2 comparisons?

Hints