LeetCode MEDIUM 380 Insert Delete GetRandom O(1) Summary
Generated by Codex with GPT-5
Quick facts
- Difficulty:
MEDIUM - Problem: Insert Delete GetRandom O(1)
- Main tags:
Array,Hash Table,Math,Design,Randomized
What the problem is really asking
The task is to design a set-like data structure with three operations:
insert(val)adds a value only if it is not already present.remove(val)deletes a value only if it is present.getRandom()returns one currently stored value, with every stored value equally likely.
The important constraint is that all three operations should run in average O(1) time.