Randomized Set — JavaScript medium interview problem
Implement a data structure that supports insert, remove, and getRandom in average O(1) time. Return an object from `createRandomizedSet()` with: - `insert(val)` → `true` if inserted (not already present), else `false` - `remove(val)` → `true` if removed (was present), else `false` - `getRandom()` → return a random element currently in the set (assume non-empty when called) Hint: Array for O(1) random + Map for O(1) index lookup; swap-with-last on remove.
Tags: hashmap, array, design
Practice this HashMap & Set problem free in the JS Interview Playground with automated tests and unlockable solutions.