Insert Delete GetRandom O(1) Problem
Insert Delete GetRandom O(1) Problem — ExecCode Medium DSA Practice
Solve the Insert Delete GetRandom O(1) problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Implement RandomizedSet with average O(1) insert, remove, and getRandom. Implement Solution.solve(ops, vals) where ops are insert / remove / getRandom and vals are parallel arguments (null for getRandom). Return the list of operation results.
Examples
Input {"ops": ["insert", "insert", "getRandom", "remove", "getRandom"], "vals": [1, 2, null, 1, null]}; Output [True, True, 1, True, 2]
Constraints
-2^31 ≤ val ≤ 2^31 - 1 At most 2·10^5 calls
Practice Insert Delete GetRandom O(1) free on ExecCode. Browse DSA problems, topic map, and placement guides.