04 Try it yourself Interactive
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.