LFU Cache: LeetCode (Design Problem)

Поділитися
Вставка
  • Опубліковано 2 січ 2025

КОМЕНТАРІ • 21

  • @omarsalem5832
    @omarsalem5832 Рік тому

    Great explanation! everywhere else just went through code, but your visualisation helped alot

  • @siddharthpandey8516
    @siddharthpandey8516 3 роки тому

    great explanation! hats off

  • @YogeshPorwal-zl9lh
    @YogeshPorwal-zl9lh Рік тому

    Amazing!!

  • @mrinal101
    @mrinal101 3 роки тому

    Thank you so much for the clear explanation

  • @Saurabh2816
    @Saurabh2816 3 роки тому +1

    Loved the simple explanation !!

  • @goutamkundu6392
    @goutamkundu6392 3 роки тому +7

    Great explanation but 1 thing needs update. For "put", if key already exists, then value needs to be updated as well as the key's frequency also needs to be updated(+1)

  • @prafulsinghvit
    @prafulsinghvit 3 роки тому +1

    If I am not mistaken, I think we can just use 2 Hashmaps instead of 3.
    1) hashMap
    This would store frequency and value nodes (Node would have value and next and prev pointer to node)
    Node()
    {
    Int value;
    Node left;
    Node right;
    }
    Second, a hashMap which stores pointer (reference) to a Node n.
    Whenever we say get (xyz) I get the address from 2nd hashMap and get value by going to that address in hashMap1.
    Thanks

    • @Abhishek.sharma499
      @Abhishek.sharma499 3 роки тому

      When you say get(xyz) and search it in Second HashMap, you get a Node, and directly go to the list in first Hashmap, and do your function. But you don't know the frequency of the xyz, where would you insert xyx after the get operation. I mean you have to increment the frequency by 1.

  • @dcdamnchill6729
    @dcdamnchill6729 3 роки тому +1

    Thank you , easily understandable to people like me 😁.

  • @niteshkhetan9757
    @niteshkhetan9757 3 роки тому +1

    Good explanation. Would like to add the reason for using doubly linked list as it is not mentioned in the video. The reason for using DLL is while deleting a node it becomes easy to delete the node directly if we have the pointer to that node from the hasmap. Bcoz while deletion we need the previous node so that we can unlink the previous node from the node to be deleted. Hence DLL comes handy as we don't have to traverse through the whole list to get the prev node.

  • @GaneshIyerrr
    @GaneshIyerrr 4 роки тому +2

    Isn't freq_keyslist[freq]erase() running in linear time?

    • @danavram8437
      @danavram8437 4 роки тому

      No. Freq to keys list is a map, so lookup is O(1) by freq. The erase is called on the doubly linked list object, and if you have the pointer - which you do, stored in key_iterator, erase is O(1). If you do not have access to the pointer, it is indeed O(N) as you need to use remove() not erase().
      www.cplusplus.com/reference/list/list/erase/ Complexity: Linear in the number of elements erased (destructions).
      Note that unlike for vectors or other ordered data structures, removing an element from the list DOES NOT invalidate any of the iterators!
      If you think about a DLL that you implement yourself, you have
      struct Node
      {
      int val;
      Node* prev = nullptr;
      Node* next = nullptr;
      }
      deleteNode(Node* toDel)
      {
      toDel->prev->next = toDel->next; // remove reference in O(1), no need to iterate
      // delete toDel; // only if allocated using new
      }

  • @chinmaym7479
    @chinmaym7479 4 роки тому +1

    can't you get the last pointer as rbegin() rather than --end() ?

  • @surbhisharma8052
    @surbhisharma8052 4 роки тому +2

    very nice explaination sir

  • @169mayan
    @169mayan 4 роки тому +4

    Nice explanation, but in the example you have taken there are only 9 keys in the freq map so putting key 11 won't remove any key.

  • @gagankalra4555
    @gagankalra4555 4 роки тому +1

    Bhaiya how to get into mba in harvard or cornell with reduced fees( financial aid/scholarship) after btech in india. Bhaiya pls reply

  • @HimanshuSharma-tm2ms
    @HimanshuSharma-tm2ms 4 роки тому +2

    beautifully explained!

  • @ektatank7652
    @ektatank7652 4 роки тому +3

    you have explained very clearly. Thank you for easy approach.

  • @thatipelli1
    @thatipelli1 3 роки тому +2

    Thank you so much. This was very clear.

  • @ashwinsayali1728
    @ashwinsayali1728 4 роки тому +2

    Perfect

  • @nabidulalam6956
    @nabidulalam6956 4 роки тому +2

    Neat and precise explanation!