Field note / fundamentals

publishedupdated 2026-05-04#algorithms#collections#map#set#weakmap

Coding Practice: Collections

Ten medium-level questions using Map, Set, WeakMap, frequency tables, grouping, caches, and lookup-heavy workflows.

TL;DR

  • Map and Set solve a huge number of frontend interview problems cleanly.
  • I practice collections as lookup, grouping, counting, dedupe, and cache problems.
  • These are often the fastest way to turn nested loops into linear-time solutions.

Context

Collections show up in role maps, route permissions, in-memory caches, deduped analytics, grouped activity streams, and optimistic entity stores.

The Approach

Practice these 10 medium-level questions:

  1. Contains Duplicate — classic Set warm-up done in one pass.
  2. Two Sum With Index LookupMap for complement search.
  3. Top K Frequent Items — pair counting with selection.
  4. Group Anagrams — normalized keys plus grouped buckets.
  5. Build LRU Cache — combine Map ordering with eviction rules.
  6. Count Unique Visitors Per Day — nested maps or map-of-sets.
  7. First Non-Repeating Character — count then scan, or ordered map strategy.
  8. Merge Preference Sources — keyed overwrite with precedence.
  9. Track In-Flight Requests — dedupe concurrent promises by request key.
  10. Build Reverse Index — map tags to matching record IDs.

Try it in the browser

Browser Practice

Collections practice: group words by frequency signature

Implement solve(words) and group words that share the same character counts.

Sample Tests
2 checks
Function name: solve
Best for JavaScript / TypeScript / JSON practice snippets.Monospace editorRuns in browser sandbox

Trade-offs

  • Collections improve lookup speed, but they make iteration order and serialization choices matter.
  • Map is often better than plain object for intent clarity, especially when keys are not simple strings.

References