NeetCode #127LC-380MediumArrays & Hashing
← Back to All Problems

#127 · #380 · Insert Delete GetRandom O(1)(O(1) 时间插入、删除和获取随机元素)

📌 Problem Statement & Constraints

Design a data structure that supports insert(val), remove(val) and getRandom() in average O(1) time. insert returns whether the value was newly added, remove returns whether the value existed, and getRandom returns a uniformly random existing element. Constraints: -2^31 <= val <= 2^31 - 1; at most 2 * 10^5 calls.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!