Insert Remove And Random in O(1)
Design a data structure that will do insert, remove and random operation in O(1) and duplicate number allowed.
Design a data structure that will do insert, remove and random operation in O(1) and duplicate number allowed.
Solution:
- Take two data structure
- List – To all numbers one by one (including duplicates)
- Map – To hold given number and their location of list DS
Latest Source Code:
Github: InsertRemoveAndRandomInO1.java
Output:
Insert 1 : true Insert 1 : false Insert 2 : true Random : 1 Remove 1 : true Random : 1