HashMap & Set

Randomized Set

medium
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.
Hint steps(0/3 revealed)
  1. 1

    Complete previous step or reveal to unlock this hint.

  2. 2

    Complete previous step or reveal to unlock this hint.

  3. 3

    Complete previous step or reveal to unlock this hint.