Problem context and objectives
Mission briefing
Puzzle systems engineer · A game mechanic is behaving incorrectly
Promote the most common values: The Frequency Podium.
Brute force may pass the demo but fail when the world fills with players.
How you win
- 1Recognize when Frequency buckets matches the clues
- 2Keep this true after every move: bucket f contains exactly the values that occur f times
- 3Reach the result within O(n)
Rules and pressure
- Target cost: O(n)
- State rule: bucket f contains exactly the values that occur f times
Lesson 1 of 3
Live algorithm trace
Frequency buckets
Complete execution1 of 6
Count all six values in one pass.
1
count every value2
buckets = n + 1 empty lists3
append value to bucket[count]4
scan frequencies from n down to 15
emit values in numeric order6
stop after k valuescounts = 1:3, 2:2, 3:1k = 2
Truth to preserve / Cost target
Truth to preserve
bucket f contains exactly the values that occur f times
Cost target
O(n)
Count each value once, then place values into buckets indexed by frequency. Scanning buckets from high to low yields the most frequent values without sorting the whole input.
Your call · What should guide every step of this algorithm?