LRU cache | Live Coding with Explanation | Leetcode

  Рет қаралды 7,105

Algorithms Made Easy

Algorithms Made Easy

3 жыл бұрын

What is LRU Cache?: • What is LRU cache?
Get Discount on GeeksforGeeks courses (practice.geeksforgeeks.org/co...) by using coupon code: ALGOMAEASY
To support us you can donate
Patreon: / algorithmsmadeeasy
UPI: algorithmsmadeeasy@icici
Paypal: paypal.me/algorithmsmadeeasy
Check out our other popular playlists:
✅✅✅[ Tree Data Structure ] : • Tree Data Structure
✅✅✅[ Graphs Data Structure ] : • Graph Data Structure
✅✅✅[ December Leetcoding Challenge ] : • December Leetcoding Ch...
✅✅✅[ November Leetcoding Challenge ] : • November Leetcoding Ch...
✅✅✅[ August Leetcoding Challenges ] : • August LeetCoding Chal...
✅✅✅[ July Leetcoding Challenges ] : • July LeetCoding Challe...
✅✅✅[ Cracking the Coding Interview - Unique String ] : • Cracking the Coding In...
✅✅✅[ June Leetcoding Challenges ] : • June LeetCoding Challe...
✅✅✅[ May Leetcoding challenges ]: • May LeetCoding Challen...
Problem Link: leetcode.com/problems/lru-cache/
Code: github.com/Algorithms-Made-Ea...
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.
#coding #leetcode #programminglife #programmingisfun #programmer #tech #software #codinglife #leetcode

Пікірлер: 14
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!! Questions you might like: ✅✅✅[ Tree Data Structure ] : kzbin.info/aero/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls ✅✅✅[ Graphs Data Structure ] : kzbin.info/aero/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C ✅✅✅[ January Leetcoding Challenge ] : kzbin.info/aero/PLJtzaiEpVo2wCalBcRcNjXQ0C6ku3dRkn ✅✅✅[ December Leetcoding Challenge ] : kzbin.info/aero/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA ✅✅✅[ November Leetcoding Challenge ] : kzbin.info/aero/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e ✅✅✅[ August Leetcoding Challenge ] : kzbin.info/aero/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe ✅✅✅July Leetcoding challenges: kzbin.info/aero/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC- ✅✅✅June Leetcoding challenges: kzbin.info/aero/PLJtzaiEpVo2xIfpptnCvUtKrUcod2zAKG ✅✅✅May Leetcoding challenges: kzbin.info/aero/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e ✅✅✅Cracking the Coding Interview - Unique String: kzbin.info/aero/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE Struggling in a question?? Leave in a comment and we will make a video!!!🙂🙂🙂
@shivendra2076
@shivendra2076 2 жыл бұрын
Under rated channel, Thanks bro, understood it
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 2 жыл бұрын
Thank you!! Do not forget to subscribe to the channel!! 😊😊
@milenitrivedi7561
@milenitrivedi7561 2 жыл бұрын
Great explanation !
@pranavananth6617
@pranavananth6617 5 ай бұрын
one of the best solution...
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 4 ай бұрын
Thank you!!
@CRamPrasannaCV
@CRamPrasannaCV 3 жыл бұрын
Understood :-)
@RupamSasmalYt
@RupamSasmalYt Жыл бұрын
Have done the same approach with c++, but it's giving TLE. Can't find any single solution in c++ without tle in leetcode :( C++ Code: class Node{ public: int key, val; Node *prev, *next; Node(int key,int val){ this->key=key; this->val=val; } }; class LRUCache { public: int cap; Node* head=new Node(0,0); Node* tail=new Node(0,0); unordered_map mp; LRUCache(int capacity) { cap=capacity; head->next=tail; tail->prev=head; } void Add(Node* newNode){ mp[newNode->key]=newNode; Node* tmp=head->next; head->next=newNode; newNode->prev=head; newNode->next=tmp; tmp->prev=newNode; } void Delete(Node* node){ mp.erase(node->key); node->prev->next=node->next; node->next->prev=node->prev; } int get(int key) { if(mp.find(key)!=mp.end()){ // key present Node* resNode=mp[key]; Delete(resNode); Add(resNode); return resNode->val; } return -1; } void put(int key, int value) { if(mp.find(key)!=mp.end()){ // key is present Delete(mp[key]); } if(mp.size()==cap){ Delete(tail->prev); } Add(new Node(key,value)); } };
@dambar67
@dambar67 Жыл бұрын
map.remove(node), how it will remove ,here key should be given not the value.
@appprocessorsappdevelopmen8405
@appprocessorsappdevelopmen8405 3 жыл бұрын
*insert() method without declaring headNext* void insert(Node node){ //insert into map map.put(node.key,node); //point node's next to head's next node.next = head.next; //point head's next' prev to node head.next.prev = node; head.next=node; node.prev=head; }
@omarkhan5223
@omarkhan5223 2 жыл бұрын
@5:40 You remove tail.prev. I thought you would remove tail because the tail of linked list is the last node, isn't tail.prev the second last node?? Why is this not the case?
@054_heenaahmed8
@054_heenaahmed8 2 жыл бұрын
tail is the dummy node that is at end of linkedlist , similar to head , which is also dummy at start of linkedlist . we have used it to simplify the operations , and get access to last(using tail) and first(using head) node in O(1).
@rilkedev449
@rilkedev449 2 жыл бұрын
@@054_heenaahmed8 Thank you.
@sayyidiskandarkhan3064
@sayyidiskandarkhan3064 Жыл бұрын
it would have been great had he covered this in the explaination but i had to look at the comments to find the results.
LRU Cache -  Explanation, Java Implementation and Demo
23:41
Bhrigu Srivastava
Рет қаралды 16 М.
What is LRU cache?
8:45
Algorithms Made Easy
Рет қаралды 7 М.
Идеально повторил? Хотите вторую часть?
00:13
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 9 МЛН
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 49 МЛН
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 15 МЛН
Simplify Path | Live Coding with Explanation | Leetcode - 71
11:08
Algorithms Made Easy
Рет қаралды 10 М.
LeetCode 146. LRU Cache (Algorithm Explained)
18:00
Nick White
Рет қаралды 116 М.
Implement LRU cache
12:25
Techdose
Рет қаралды 122 М.
Partition List | Live Coding with Explanation | Leetcode - 86
6:03
Algorithms Made Easy
Рет қаралды 11 М.
Reverse Nodes in k-Group O(1) | Live Coding with Explanation | Leetcode - 25
15:25
Shortest Path in Binary Matrix | Live Coding with Explanation | Leetcode - 1091
10:23
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН