dsa · medium
Insert Delete GetRandom O(1)
GreyOrangeHash MapArrayDesign
RandomizedSet: insert(val) true if newly added, remove(val) true if present, getRandom uniform over current values. Tests only call getRandom when the set has **exactly one** value (so the answer is determined).
Fill in the RandomizedSet class. The starter already walks ops / args and calls your methods — leave the driver at the bottom as-is. Constructors contribute null; booleans print as true / false.
**Example**
`` RandomizedSet() → null insert(1) → true remove(2) → false insert(2) → true remove(1) → true getRandom() → 2 insert(2) → false ``
Constraints
Calls <= 1000. getRandom only when size==1 in these tests.
Examples
Example 1
Input: ["RandomizedSet","insert","remove","insert","remove","getRandom","insert"] [[],[1],[2],[2],[1],[],[2]] Expected: [null,true,false,true,true,2,false]