Skip to content
Uhini0201 edited this page Jun 1, 2020 · 1 revision

Welcome to the nsert-Delete-GetRandom-O-1---Duplicates-allowed wiki!

# Design a data structure that supports all following operations in average O(1) time.

_Note: Duplicate elements are allowed._ _insert(val): Inserts an item val to the collection._ _remove(val): Removes an item val from the collection if present._ _getRandom: Returns a random element from current collection of elements. The probability of each element being returned is linearly related to the number of same value the collection contains._ [Naive but accurate appraoch](https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/)

Clone this wiki locally