filmov
tv
Design data structure | Insert Delete GetRandom O(1) | Leetcode #380
Показать описание
This video explains a very important design based programming interview problem which is to design a data structure where INSERT, DELETE and GET-RANDOM can be performed in just O(1) average time.The implemented data structure will be just like a SET where we can't have duplicates.I have explained 3 intuitive data structures which can be chosen to solve thisproblem.The most intuitive data structure is array or vector but DELETE operation is O(N) for array.The next intuitive data structure is SET but GET RANDOM is O(N) for it.The third intuitive data structure is a doubly linked list where DELETE and GET-RANDOM operations are both O(N). The problem is to access elements by value in just O(1). Array has O(1) random access by index but not by value.The idea for this is to store the address or index of every element in a MAP where key is element itself and value is the index where the element is located.This problem can be solved by using ARRAY+MAP or Doubly Linked List + MAP but array implementation is easier and so i have shown that implementation using example.At the end of the video,i have shown the code walk through.CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
=================================================================
=================================================================
SIMILAR PROBLEMs:-
=================================================================
=================================================================
SIMILAR PROBLEMs:-
Комментарии