04 Try it yourself Interactive

Watch the map fill up, one item per press

The same list, two questions. Frequency map reads every item and remembers how many times each key turned up. Duplicate check keeps a set instead and stops the instant a value comes back. Watch the two-column table on the right: while items are still being read, each press either adds a row or changes a number in one. The last press or two only reads the answer off.

Frequency map · key → count
one pass · O(n) time, O(k) space
A word like BANANA, or 2–10 items separated by commas.
input · one item read per press
Map · key → count
Press Next to begin. Each press reads one item.


      
Item
Distinct keys0
New keys0
Repeats0
step 0 / 0