leetle

Daily challenge for 2025-09-17

260. Insert Delete GetRandom O(1)

Implement the RandomizedSet class with the following methods:
insert(val): Inserts an item into the set. Returns true if not present, false otherwise.
remove(val): Removes an item from the set. Returns true if present, false otherwise.
getRandom(): Returns a random element. Each element has equal probability.

All operations should run in O(1) average time. For this problem, return the size of the set after a sequence of operations.

Example:
Input: ["insert", "remove", "insert", "getRandom", "remove"], [[1], [2], [2], [], [1]]
Output: 1 (final set size)

Run this challenge interactively in Python or JavaScript when the app loads.