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 Frequency Podium

Learn
Play
Prove
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

  1. 1Recognize when Frequency buckets matches the clues
  2. 2Keep this true after every move: bucket f contains exactly the values that occur f times
  3. 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 execution
1 of 6

Count all six values in one pass.

1count every value
2buckets = n + 1 empty lists
3append value to bucket[count]
4scan frequencies from n down to 1
5emit values in numeric order
6stop after k values
counts = 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?

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