Implement LRU Cache | C++ and Java Clean and Short Implementation

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2024

ความคิดเห็น • 181

  • @takeUforward
    @takeUforward  3 ปีที่แล้ว +154

    If you are coming from watching the previous video explanation, do comment

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      bhaiya one question, did you delete ur video " stack using 2 queues?" if you did then why so ?

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว

      @@freshcontent3729 playlist ke h toh.. check kro, galat upload hua tha, th replace kie.

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      @@takeUforward check kiya it showes privated in playlist

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว

      th-cam.com/video/jDZQKzEtbYQ/w-d-xo.html
      Isime dono hai..

    • @10online57
      @10online57 3 ปีที่แล้ว +1

      Coming from the previous video bhaiya 💥💥💥💥

  • @mynkprtp
    @mynkprtp 2 ปีที่แล้ว +5

    We can free memory by delete or free operation on the LRU node which is to be deleted when put is performed when cache size is exceeded.

    • @DeepSingh-zs2oi
      @DeepSingh-zs2oi 2 ปีที่แล้ว

      Yes, otherwise there is no need to erase the map element....because the node remains the same.

  • @AdityaSoni-sw8fc
    @AdityaSoni-sw8fc 3 ปีที่แล้ว +18

    Couldn't get a better explanation than this. Thanks bhaiya.
    You are doing a great job helping us.
    Expecting more such explanatory videos

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว +1

      what will be the space compleixty of stirivers code ?

  • @techzone2577
    @techzone2577 3 ปีที่แล้ว +14

    Can you make a series for dp????
    You as a teacher is really awesome, can connect with you.

    • @AbhishekVerma-yw1ps
      @AbhishekVerma-yw1ps 3 ปีที่แล้ว +8

      Follow Aditya Verma's DP playlist. He is considered as God of DP !

    • @nikhilchaudhary9123
      @nikhilchaudhary9123 3 ปีที่แล้ว

      @@AbhishekVerma-yw1ps any playlist for backtracking

  • @stith_pragya
    @stith_pragya 6 หลายเดือนก่อน +2

    UNDERSTOOD......Thank You So Much for this wonderful video.......🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @kumarivandana1554
    @kumarivandana1554 3 ปีที่แล้ว +12

    Is it necessary to erase key from map which is already present? I think that will automatically be overwritten when we assign new value to the key

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว +7

      Yes no need, i did an extra step there

    • @jayanth1191
      @jayanth1191 2 ปีที่แล้ว

      Same doubt 😂

    • @pranshu_awasthi
      @pranshu_awasthi 2 ปีที่แล้ว +4

      Make sure to change the code a little bit
      void put(int key_, int value) {
      if(m.find(key_) != m.end()) {
      node* existingnode = m[key_];
      m.erase(key_);
      deletenode(existingnode);
      }
      if(m.size() == cap) {
      m.erase(tail->prev->key);
      deletenode(tail->prev);
      }
      Suppose , you're commenting the m.erase line , in that case make sure that the if statement below , where we're checking if the size of map is equal to cap , is changed as follows :
      ELSE IF (m.size() == cap) {
      m.erase(tail->prev->key);
      deletenode(tail->prev);
      }
      See , that I've changed the if to else if.
      WHY ?
      See , since we're not deleting the key-val pair from the map , the map might be full , and if the earlier code is written , the control flow would check if the map is full and thus would delete the LEAST RECENTLY USED NODE , causing us trouble.
      Thus , the ELSE IF.

    • @akarsh1821
      @akarsh1821 2 ปีที่แล้ว

      @@takeUforward No No, it is not an extra step, it is absolutely correct. If you remove it the map.size()==capacity condition will hit and this messes up the answer as a node will be deleted unintentionally (According to the java code shown). I have checked this.

  • @Spider-Man_67
    @Spider-Man_67 2 ปีที่แล้ว

    Aditya bhai, isse acha explanation and code kahi aur nahi mila, Thanks!!!

  • @neetisaharan1340
    @neetisaharan1340 3 ปีที่แล้ว +2

    Couldn't get a better explanation than this.

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      what will be the space compleixty of stirivers code ?

  • @_kidrah
    @_kidrah 3 หลายเดือนก่อน

    Hats off for that simple Java code!!

  • @doingsneakypeakylike
    @doingsneakypeakylike 3 ปีที่แล้ว +8

    Thank you so much! Your explanations are always top notch!

  • @RahulSingh-de6tb
    @RahulSingh-de6tb 2 ปีที่แล้ว +2

    Great teaching, you makes everything clear, without diving into code.
    one suggestion : you should free up space of node which is deleted in dll.

    • @sharatmalkhed7543
      @sharatmalkhed7543 2 ปีที่แล้ว +1

      in java , we need not do that , jvm's garbage collector will take care of it. in c++ yes we should dealloc

  • @akshatgupta368
    @akshatgupta368 3 ปีที่แล้ว +8

    Striver Sir, Knowledge Gate's lectures are no more free, the playlist on TH-cam has private videos, I request to please tell the alternative for learning OS DBMS CN for SDE interview. Should I go for GFG's CS Fundamentals?
    Thank You.

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว +6

      I have made a video on this on the other channel..

  • @sankalpietechtips
    @sankalpietechtips 9 หลายเดือนก่อน

    DUDEEE!
    It got accepted, and the explanation is sooo simple too.

  • @The_Gurugram_Voyager
    @The_Gurugram_Voyager 3 ปีที่แล้ว +9

    I didn't think I'll wait for this question this long. Gr8 explanation 🔥🔥

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว +2

      we can do this question using queue too right ?? what is the advantage of using Doubly linked list like striver did ? Please tell.

    • @vedantsharma5876
      @vedantsharma5876 2 ปีที่แล้ว +2

      @@freshcontent3729 Queue's Delete operation would not be in O(1)

    • @inclinedscorpio
      @inclinedscorpio 2 ปีที่แล้ว

      ​@@freshcontent3729 Looks like you didn't understood the core concept. In queue, how will you get the address of data required in O(1).
      get() function will become a mess as first you will need to search data, delete it, shift all remaining data*, reinsert data O(N). put() method won't be easy as well, we want something like last in access to be O(1) while as we will have queue, it will be O(N) -> as we are using queue(FIFO).
      Due to these intracacies we are not using queue. Obviously you can use queue if asked by interviewer for fun :)

    • @PandeyAvinesh
      @PandeyAvinesh ปีที่แล้ว

      @@freshcontent3729 moving node will be of O(1) tc where as in queue it will be O(N)

  • @pabitrakb5291
    @pabitrakb5291 ปีที่แล้ว +3

    Awesome explanation!!
    Thank you for your efforts 💝

  • @shivangisrivastava1158
    @shivangisrivastava1158 2 ปีที่แล้ว +1

    Literally GBU for such exceptional rich content!

  • @vivekgupta_3085
    @vivekgupta_3085 2 ปีที่แล้ว

    So What if this video is old , Love Your Content Bhaiya , Jaruri thori na sirf dp series mai commment kru Jo Jo acha lage Usme comment krunga

  • @abhishekdeshmukh5236
    @abhishekdeshmukh5236 5 หลายเดือนก่อน

    best tutorial on this question!!!!

  • @decostarkumar2562
    @decostarkumar2562 3 ปีที่แล้ว +2

    Can we take priority queue of linked list to solve this ?

  • @afrahriyaz9388
    @afrahriyaz9388 2 ปีที่แล้ว +4

    Why not use list STL instead of implementing doubly linked list by yourself?

  • @mohithguptakorangi1766
    @mohithguptakorangi1766 3 ปีที่แล้ว +2

    You have a course on GFG ? Can you provide details or the link?

  • @rohan8758
    @rohan8758 6 หลายเดือนก่อน +1

    Khatarnaak bhaishab, Maja aa gaya, Dono video dekh kr LRU cache ke. The first algorithm was explained & in this code walkthrough is explained extremely well ❤️‍🩹

  • @aakashrajchittimalla2604
    @aakashrajchittimalla2604 2 ปีที่แล้ว +1

    Great explanation! instead of m.find(key)!=m,end( ) .. we can use m[key]!=NULL;

  • @kushalappaca5324
    @kushalappaca5324 ปีที่แล้ว +2

    In your SDE sheet, why is this llisted under Stacks and Queues even though stack or
    queue is not used here..?

    • @aneesahmad05
      @aneesahmad05 8 หลายเดือนก่อน

      same doubt

  • @TheMinino123
    @TheMinino123 2 ปีที่แล้ว +1

    Beautiful explanation. Thanks a lot!!!!!!!!!

  • @hannanhub1717
    @hannanhub1717 7 หลายเดือนก่อน +1

    java code at 07:40

  • @thatindianboy2817
    @thatindianboy2817 2 ปีที่แล้ว

    What is the point of keeping key and value, both in the node???

  • @devanshmesson2777
    @devanshmesson2777 2 ปีที่แล้ว +1

    Thank you so much striver!

  • @aswithasai4015
    @aswithasai4015 ปีที่แล้ว

    very well explained thank you

  • @varunpalsingh3822
    @varunpalsingh3822 9 หลายเดือนก่อน

    7:42 for java explanation

  • @subhasishdas3011
    @subhasishdas3011 3 ปีที่แล้ว +2

    Why are we storing key in the linkedlist node ? only storing value will be enough right as we have key in hashmap. Is there any significance of it ?

    • @purellajajisaipavankumar651
      @purellajajisaipavankumar651 3 ปีที่แล้ว

      we are accessing the element(if present) from the LinkedList

    • @mayankmishra3246
      @mayankmishra3246 3 ปีที่แล้ว

      when we have to make the node as recent used node we have to search that particular node from linked list and have to delete it and again have to add it......so if we will not add that particular node in map we have to traverse whole linked list for that.

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว +1

      @@purellajajisaipavankumar651 we can do this question using queue too right ?? what is the advantage of using Doubly linked list like striver did ? Please tell.

    • @purellajajisaipavankumar651
      @purellajajisaipavankumar651 3 ปีที่แล้ว

      @@freshcontent3729 Accessing and deleting and inserting is easy in dll compared to queue or a linked lisr

  • @satishbirhade8369
    @satishbirhade8369 3 ปีที่แล้ว

    Your often talk about engineering students or iit, nit, nsit, iiit students plz talk about and make Roadmap for bsc msc computer science non engineering students

  • @ankushroy5606
    @ankushroy5606 3 ปีที่แล้ว +1

    7:39 java solution

  • @manyagupta8679
    @manyagupta8679 4 หลายเดือนก่อน

    Thank you so much!!!😊

  • @BOSS-s6w8w
    @BOSS-s6w8w ปีที่แล้ว

    striver bhai kabhi ruknna mat keep foreward amazing explanation bhai😘

  • @Xp-Sam
    @Xp-Sam 2 ปีที่แล้ว +2

    Can somebody please clear my doubt?
    The deletenode call inside get method is only breaking the link for resnode, and we are assigning the same node after head in addnode call, so why are we updating the corresponding address in the map?
    I think there is no neee to write
    m[key_] = head->next;

    • @hrithik7354
      @hrithik7354 2 ปีที่แล้ว +1

      right no need to write m[key_] = head->next as well as mp.erase(key) in get method

    • @aadharjain313
      @aadharjain313 11 หลายเดือนก่อน

      that's what I was thinking. We are not actually deleting nodes. We are just severing links between the node to be deleted from its adjacent nodes. However in add node we are actually creating new node with the same key and new value. A new node will have new address , so needs to be updated in the map.
      Also, when putting a node in the cache (key of which already exists in map) , we could just have changed the links to move it next to head. However when putting a node with new key , we are required to create a new node. In that case we would have to define 2 different functions:-
      1. for putting already present keys (just change the links, don't create new node)
      2. for putting new keys (new node is required to be made)
      So, to avoid making seperate functions for them , striver just did that using a single function for both cases where he always deletes the old node(if exists in map) and create a new node and add it after head.

  • @PandeyAvinesh
    @PandeyAvinesh ปีที่แล้ว +2

    Use list in C++ stl as it will reduce code and make it more easier to understand and will also lead to cleaner code
    class LRUCache
    {
    list l;
    unordered_map m;//to check in O(1) and
    int size;
    public:

    LRUCache(int capacity)
    {
    size=capacity;
    }
    int get(int key)
    {
    if(m.find(key)==m.end())
    return -1;
    l.splice(l.begin(),l,m[key]);
    return m[key]->second;
    }
    void put(int key, int value)
    {
    if(m.find(key)!=m.end())
    {
    //splice moves the node poninting by iterator at 3 to iterator before first argument in list l which is 2nd element
    l.splice(l.begin(),l,m[key]);
    m[key]->second=value;
    return;
    }
    if(l.size()==size)
    {
    auto d_key=l.back().first;
    l.pop_back();
    m.erase(d_key);
    }
    l.push_front({key,value});
    m[key]=l.begin();
    }
    };

    • @rishikachopra9094
      @rishikachopra9094 ปีที่แล้ว

      hey thanks for suggestion ,it would have been more helpful if it was more of a detailed explanation

    • @danishsharma496
      @danishsharma496 ปีที่แล้ว +2

      bro nice implementation , but splice function has linear time complexity

  • @shastriamisha
    @shastriamisha 2 ปีที่แล้ว

    Amazing Explanation, thank you

  • @freshcontent3729
    @freshcontent3729 3 ปีที่แล้ว

    what will be the space compleixty of stirivers code ?

  • @SuperWhatusername
    @SuperWhatusername 2 ปีที่แล้ว

    Thank you so much

  • @SuperWhatusername
    @SuperWhatusername 2 ปีที่แล้ว

    Do we have implementation of hashmap or unordered map in C++?
    I tried searching other content on your channel but not able to find one.
    Can any one please provide the link for implentation of hashmap or unordered map in C++?

  • @vidhijain4554
    @vidhijain4554 3 ปีที่แล้ว

    Thanks for great explanation!!

  • @242deepak
    @242deepak ปีที่แล้ว

    why are we deleting when we need to move a node to the front?

  • @animehub846
    @animehub846 3 ปีที่แล้ว +1

    Not only LRU Cache, I revised linked list and doubly linked list from this video

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      what will be the space compleixty of stirivers code ?

    • @visheshkaran7083
      @visheshkaran7083 2 ปีที่แล้ว

      @@freshcontent3729 O(2N) where n is number of keys throughout the question.

  • @anveshasharma2726
    @anveshasharma2726 2 ปีที่แล้ว

    Great explanation

  • @v.sreesairam9488
    @v.sreesairam9488 3 ปีที่แล้ว

    much needed video bhaiya thank you very much :)

  • @_hulk748
    @_hulk748 ปีที่แล้ว

    Thankyou sir🙏🙇‍♂❤

  • @arvindrishi8514
    @arvindrishi8514 3 ปีที่แล้ว

    Amazing explanation 👍🏻

  • @tejasu8226
    @tejasu8226 7 หลายเดือนก่อน

    head->next = tail;
    tail->prev = head;
    Why is this written inside LRUCache(){} ?
    It shows error when written right after head and tail are both initialized. Why?
    Please explain someone🙏

  • @RahulVerma-fz2jf
    @RahulVerma-fz2jf 2 ปีที่แล้ว

    Awesome videos man. Loved it.

  • @himanshidafouty347
    @himanshidafouty347 4 หลายเดือนก่อน

    Understood

  • @mrbeast00000
    @mrbeast00000 2 ปีที่แล้ว +2

    Gives TLE on leetcode even after using map instead of unordered map

  • @ritankarsarkar9394
    @ritankarsarkar9394 3 ปีที่แล้ว

    In 0:51 LRUCache is a constructor for the class right?

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว +1

      Yes

    • @ritankarsarkar9394
      @ritankarsarkar9394 3 ปีที่แล้ว

      😍 raj bhaiya raat 3 baje comments me doubts solve kar rahe hai 🔥🙏 can't thank you enough for the effort.
      Paid courses me itna support nahi milta ❤️

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว +7

      @@ritankarsarkar9394 haha, koi doubt puche th bata dena chye agar aata ho, mera hardly 5 sec jaega.

    • @ritankarsarkar9394
      @ritankarsarkar9394 3 ปีที่แล้ว

      Big fan sir 🙇

  • @ayushi10sahu
    @ayushi10sahu 2 ปีที่แล้ว

    JUST AMAZING

  • @sunnykakrani7830
    @sunnykakrani7830 3 ปีที่แล้ว

    hey striver bhai key_ ye kyu use kia h har jagah we can use simple key as well .

  • @mohitsingh7793
    @mohitsingh7793 ปีที่แล้ว +1

    I thing my code is better than strivers's code in terms of code-readability :
    class Node {
    public:
    Node *next;
    Node *prev;
    int key;
    int val;
    Node(int key, int val)
    {
    this->key = key;
    this->val = val;
    prev = next = NULL;
    }
    };
    class LRUCache {
    public:
    int capacity;
    unordered_maph;
    Node *head, *tail;
    LRUCache(int capacity) {
    this->capacity = capacity;
    head = new Node(-1, -1);
    tail = new Node(-1, -1);
    head->next = tail;
    tail->prev = head;
    }
    int get(int key) {
    if (h.find(key) != h.end())
    {
    int value = h[key]->val;
    Node *temp = h[key];
    h.erase(key);
    removeNode(temp);
    insertNode(key, value);
    return value;
    }
    return -1;
    }
    void removeNode(Node *temp)
    {
    Node *curr = temp->next;
    Node *prev = temp->prev;
    prev->next = curr;
    curr->prev = prev;
    }
    void insertNode(int key, int value)
    {
    Node *curr = new Node(key, value);
    h[key] = curr;
    curr->next = head->next;
    head->next = curr;
    curr->prev = head;
    curr->next->prev = curr;
    }
    void put(int key, int value) {
    if (h.find(key) != h.end())
    {
    Node *temp = h[key];
    h.erase(key);
    removeNode(temp);
    }
    if (h.size() == capacity)
    {
    Node *prev = tail->prev;
    h.erase(prev->key);
    removeNode(prev);
    }
    insertNode(key, value);
    }
    };

  • @barshapal_1227
    @barshapal_1227 3 ปีที่แล้ว

    Thanku... Brother❤❤❤... New subscriber

  • @aravindravva3833
    @aravindravva3833 2 ปีที่แล้ว +1

    Java 07:41

  • @satyamabhishek1317
    @satyamabhishek1317 3 ปีที่แล้ว

    Great Explanation bro :)

  • @sagnikmitra710
    @sagnikmitra710 3 ปีที่แล้ว

    Great explanation🔥🔥revisrd dll😁

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      what will be the space compleixty of stirivers code ?

  • @AdityaSharan811
    @AdityaSharan811 3 ปีที่แล้ว

    Please discuss java implementation for next question.

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว +1

      We have discussed it here too..

  • @udaytewary3809
    @udaytewary3809 ปีที่แล้ว

    Coming from the previous vedio bhaiya

  • @ankitbhardwaj9566
    @ankitbhardwaj9566 3 ปีที่แล้ว

    I was just wondering how the add in get was working , this is working addnode(new node(key_,res));

  • @jayadubey_22
    @jayadubey_22 3 ปีที่แล้ว +1

    Great teaching always 🙌

  • @manojnavinjamuri5867
    @manojnavinjamuri5867 ปีที่แล้ว +1

    why doubly linkedlist why not just linkedlist?

  • @roughuse.jaiganesh
    @roughuse.jaiganesh 2 ปีที่แล้ว

    understood.

  • @fahmidhossainSakib
    @fahmidhossainSakib 2 ปีที่แล้ว

    Striver, you are amazing.
    I cannot really wrap my mind around the fact that at such young age(so young that he is calling the nodes as "guy" signifies the fact that his vocab is very limited) he has gained so much skills.

    • @anurondas3853
      @anurondas3853 ปีที่แล้ว +3

      I could not see the correlation between calling a node as "guy" and having limited vocab though😅😅.

  • @satyampande684
    @satyampande684 2 ปีที่แล้ว

    understood!!

  • @geekySRM
    @geekySRM 2 ปีที่แล้ว

    Awesome!!

  • @nagame859
    @nagame859 ปีที่แล้ว

    🥳

  • @aasthajha1051
    @aasthajha1051 3 ปีที่แล้ว

    great great great!!!!!!!!!!!!

  • @satvrii
    @satvrii ปีที่แล้ว

    ❤❤

  • @deepanshu6576
    @deepanshu6576 ปีที่แล้ว

    Bro put method implementation is wrong here, it should be else if(cap == mp. size()), as when someone updates a key that already exists there in the map and the size is full then in that case we don't need to remove the least recently used node as we are to inserting any new node we are just updating existing node there

  • @srijanshahi8587
    @srijanshahi8587 2 ปีที่แล้ว

    The C++ sol is giving TLE IN leetcode

  • @manikantsharma6108
    @manikantsharma6108 2 ปีที่แล้ว +1

    I am getting TLE , wrote the same code , what to do?

    • @Vivek-hf7mx
      @Vivek-hf7mx 2 ปีที่แล้ว +1

      Use a normal map instead of unordered map ur soln will be accepted

    • @manikantsharma6108
      @manikantsharma6108 2 ปีที่แล้ว

      @@Vivek-hf7mx Thanks brother it's working

    • @asutoshmahapatro5708
      @asutoshmahapatro5708 2 ปีที่แล้ว

      @@manikantsharma6108 it is still not working..
      map < int, node * > m;

  • @bone_doctor_yeet
    @bone_doctor_yeet 2 ปีที่แล้ว +1

    Unordered_map will give TLE in leetcode, use map

    • @pranavsharma7479
      @pranavsharma7479 2 ปีที่แล้ว

      wht ? why i dont think so

    • @bone_doctor_yeet
      @bone_doctor_yeet 2 ปีที่แล้ว

      @@pranavsharma7479 it happened with me...i know unordered map has avg complexity of 1 and map has logn but still they must have made test cases so that worstcase of unordered map was applicable. Anyways, my code was giving tle on last few TCs with unordered map but ran successfully with map

  • @tusharbarman1924
    @tusharbarman1924 ปีที่แล้ว

    I don't think i will ever be able to come with a solution like this. I will most likely remain dumb.

  • @kartiksrivastava3897
    @kartiksrivastava3897 2 ปีที่แล้ว

    yes yes yes

  • @nagame859
    @nagame859 ปีที่แล้ว

    Done

  • @abhayrai1724
    @abhayrai1724 3 ปีที่แล้ว

    Amazing bhaiya 🔥🔥🔥🔥🔥

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      we can do this question using queue too right ?? what is the advantage of using Doubly linked list like striver did ? Please tell.

  • @thecodingrookie
    @thecodingrookie 8 หลายเดือนก่อน

    Nice

  • @panchadichandanasai5084
    @panchadichandanasai5084 2 ปีที่แล้ว

    I am getting TLE while submitting the same code

  • @ayushkhandelwal3932
    @ayushkhandelwal3932 2 ปีที่แล้ว

    Thank you bhaiya for explaining...but leetcode pr mere TLE de raha h...apka code bhi copy paste krke dekh liya ...helpMe( please, 🙏 );

  • @RishiRaj-by5bn
    @RishiRaj-by5bn 2 ปีที่แล้ว +1

    It is giving TLE on leetcode :( for two test cases.

    • @Vivek-hf7mx
      @Vivek-hf7mx 2 ปีที่แล้ว +1

      Use a normal map instead of unordered map ur soln will be accepted

  • @amansamal8233
    @amansamal8233 2 ปีที่แล้ว

    understood❤❤

  • @utkarshvashisth2793
    @utkarshvashisth2793 2 ปีที่แล้ว

    There will be memory leak not deleting the node just changing the links

  • @samarthpandya1194
    @samarthpandya1194 2 ปีที่แล้ว

    OP!!!!

  • @adarshrai9516
    @adarshrai9516 3 ปีที่แล้ว

    🔥🔥

  • @tarunakantakumbhar5725
    @tarunakantakumbhar5725 3 ปีที่แล้ว +1

    Bhaiya can you help me to solve this problem or any suggestion (how to make a plugin for upload a csv file in wordpress and display each line in dashboard ?)

  • @KratosProton
    @KratosProton ปีที่แล้ว

    Ye

  • @neerajkumar5506
    @neerajkumar5506 2 ปีที่แล้ว

    it showing TLE when submitting on leetcode (same code as above in c++) why? can anyone help please

    • @Vivek-hf7mx
      @Vivek-hf7mx 2 ปีที่แล้ว

      Use a normal map instead of unordered map ur soln will be accepted

  • @swapnanilgupta3046
    @swapnanilgupta3046 3 ปีที่แล้ว

    Sooooo good

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      we can do this question using queue too right ?? what is the advantage of using Doubly linked list like striver did ? Please tell.

    • @swapnanilgupta3046
      @swapnanilgupta3046 3 ปีที่แล้ว

      @@freshcontent3729 I think the main advantage of using DLL was the ease with which he was able to reorder the recently used item with O(1) time. I dont think you will be able to do that in O(1) with queues. Not completely sure though.

  • @nidhishprasad2506
    @nidhishprasad2506 2 ปีที่แล้ว

    Given C++ code is giving time limit exceeded error on Leetcode.Can someone please provide working code?

    • @janvisoni2680
      @janvisoni2680 2 ปีที่แล้ว

      Use a normal map instead of unordered map ur soln will be accepted

  • @AmanKumarSinhaOfficial
    @AmanKumarSinhaOfficial 3 ปีที่แล้ว +2

    Please make a roadmap for BCA Students...

  • @anandsahoo3711
    @anandsahoo3711 5 หลายเดือนก่อน

    chumma code deya hai bro

  • @karanudayandas1608
    @karanudayandas1608 3 ปีที่แล้ว +2

    Bhai this solution in leetcode shows the following:-
    Runtime: 436 ms, faster than 12.57% of C++ online submissions for LRU Cache.
    Memory Usage: 178.6 MB, less than 5.02% of C++ online submissions for LRU Cache.
    Is there a better way to solve this question or is this sufficient enough?

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว +14

      Leetcode runtime err is a myth, its not correct always..keeps fluctuating..
      Focus on asymptotic complexity

    • @karanudayandas1608
      @karanudayandas1608 3 ปีที่แล้ว

      Ok thank you bhai👍👍

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      we can do this question using queue too right ?? what is the advantage of using Doubly linked list like striver did ? Please tell.

    • @takeUforward
      @takeUforward  3 ปีที่แล้ว +2

      @@freshcontent3729 delete in o(1)

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      @@takeUforward thanks, so in interview which apporach should I tell ? both or this one ?

  • @nidhigupta9909
    @nidhigupta9909 3 ปีที่แล้ว

    I don't think there's any need of changing the address of key in get method coz we are assigning the same node to head->next. correct me if i am wrong.

  • @honestad3558
    @honestad3558 4 หลายเดือนก่อน

    Who also gets oyo ad😂

  • @newanurag
    @newanurag ปีที่แล้ว

    Sorry to say but it is a wrong and very inefficient implementation. Reasons highlighted:
    1) No relation between hashmap and linked list. What is the point of keeping Linked list?
    2) In case of successful get operation, entry from hashmap and linklist is deleted and added. Honestly, successful get operation should not change hashmap.
    3) Put operation should come into place when get operation is unsuccessful. Because if cache is miss then data should be readback from datastore/backend/disk/device and then populate the hashmap using put operation.
    4) Find operation of hashmap should be close to O(1), which will not be the case here if more than one get operation is successful for a given key because hashmap is modified.
    5) Periodic timer thread should be there to check if cache/hashmap is near to full then free up the entries in the background, otherwise if the cache is full then last cache hit/get operation will always be slow.
    Thanks!

  • @de-codr8814
    @de-codr8814 3 ปีที่แล้ว

    First 🥇