Table of Contents: (I'm screaming in this video. I know. I am sorry.) Messing Around 0:00 - 0:23 Problem Introduction 0:23 - 0:36 What Does LRU (Least Recently Used) Mean? 0:36 - 1:10 Short Example of The LRU Policy 1:10 - 2:28 What Is A Cache? 2:28 - 2:53 What Is An LRU Cache? 2:53 - 3:12 The Properties of An LRU Cache 3:12 - 6:44 LRU Cache Operations Walkthrough 6:44 - 12:18 Summarizing The Ideas 12:18 - 12:53 More Subscriber Begging 12:53 - 13:12 Notes: 10:52 -> We need the nodes to hold their own keys. This matters when the LRU entry is evicted when capacity is surpassed. We just pop the item from the doubly linked list's end BUT I made the mistake to say the nodes won't need keys. They will need their respective key. We need the removed node's key to remove it from the hashtable since it is now out of the cache completely. Comments: Yes. I am screaming. I know. I messed up the first like 30 videos because I was still learning audio. The code is in the description. Note, we could also use Java's LinkedHashMap, but I choose to use this code example since it takes all that abstraction away so you see all of the critical operations that need to be taken care of if you were to really implement this.
@evanxg8520005 жыл бұрын
It's ok to scream bro, it's just that passion driving you I guess. loving the channel.
@BackToBackSWE5 жыл бұрын
@@evanxg852000 hahahahha, nah, I just didn't have a mic
@michaelfekadu61165 жыл бұрын
THANK YOU FOR SCREAMING! IT MADE LRU CACHE MAKE MORE SENSE! THIS VIDEO IS MORE MEMORABLE 😫😄
@toprank96024 жыл бұрын
@@BackToBackSWE is this a system design question?
@asifbherani34904 жыл бұрын
Such a nice explanation but very disappointing end to it as we dont have the code in description. Please update the video and description :(
@MostafaAliMansour5 жыл бұрын
This channel is underrated, dude u r really awesome !
@BackToBackSWE5 жыл бұрын
Let's increase the rating
@RohitKumar-so9ik5 жыл бұрын
Yup seriously this man is way more than what we predict through his subs!!
@srijaanand27934 жыл бұрын
Cannot appreciate enough how well you explain the problem, and not just read out the problem statement and code! Sometimes just understanding the code is required but often I need an in-depth understanding of the question and what was the thought process etc. Whenever I come across a question like that, I just hope that you would have made a video on it and come to your channel :)
@BackToBackSWE4 жыл бұрын
sure, and great to hear
@TKNinja0072 жыл бұрын
Great video, I love how you spent the entire video breaking down the concepts instead of showing any code.
@BackToBackSWE2 жыл бұрын
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@maripaz56504 жыл бұрын
just answered this question yesterday in an interview, bless your channel. Thanks to you, I was able to stumble upon the optimal solution a lot quicker than if I was working on my own!
@BackToBackSWE4 жыл бұрын
great
@sddhrtha5 жыл бұрын
I have my campus recruitment in a month, and your entire channel is on my revision list. Dude, I can't thank you enough for making these high-quality videos.
@BackToBackSWE5 жыл бұрын
yw, go get the offer now! haha, u can do it
@zummotv10135 жыл бұрын
DataStructure and Algo group on WhatsApp.Please Join chat.whatsapp.com/GKVxU5dvU1e3v7h9ctDpXn
@ninja35143 жыл бұрын
u Got a Job now?
@zahranajib55283 жыл бұрын
Your energy and spirit is unmatched. Love ya man
@ANGELINK9995 жыл бұрын
I feel so lucky that I found your channel. Your videos are so easy to understand. You're awesome!
@BackToBackSWE5 жыл бұрын
Thanks haha - shameless plug, releasing a course in 1-2 months - it'll be 🔥
@snowing9065 жыл бұрын
Wow how is this channel so underrated. I feel like I found hidden treasure and I want others to also find it...
@BackToBackSWE5 жыл бұрын
Let's add to the treasure.
@kevin-lg3hs5 жыл бұрын
There's always a Back To Back SWE video to explain the leetcode problem that confused me. Thanks!!!!!
@BackToBackSWE5 жыл бұрын
haha
@zummotv10135 жыл бұрын
DataStructure and Algo group on WhatsApp.Please Join chat.whatsapp.com/GKVxU5dvU1e3v7h9ctDpXn
@giannizamora72473 жыл бұрын
I'm about a month into my DS&A study and so many data structures and principles just clicked. Thank you for this!!!
@aditisaha995 жыл бұрын
Really great channel. The level of energy you have is insane. It motivates me more to put more energy to practice and prepare. very well explained and great content. you earned my subscription. Specially with the weather outside when you feel sleepy and dull and cant read more than a page, this is a must watch channel for anyone who is preparing for interviews in this season. Don't change your style :)
@BackToBackSWE5 жыл бұрын
will do
@hihistorystory6 ай бұрын
Been watching many tutorial resource these days. This is the best video. Wish I've seen this in the beginning and saved a lot of my time watching others.
@wadichemkhi5 жыл бұрын
insane level of energy
@BackToBackSWE5 жыл бұрын
lol, old video, I was crazy. Still am.
@danni61135 жыл бұрын
This channel is so underrated. Great work!
@BackToBackSWE5 жыл бұрын
wassup
@shivakrishna72934 жыл бұрын
I think u r not an employee u r a perfect teacher i have seen very few people like you sir awesome
@BackToBackSWE4 жыл бұрын
ok lol
@EcheChanga3 жыл бұрын
Didn't understand this problem until I watched n I been looking at it for days Bless you brother.....and the energy made this so dope
@abcdeereijgfhd32152 жыл бұрын
Holy shoot~! I 've never thought about a double-linked list on this. Thank you for your clarification.
@amansinhparmar33364 жыл бұрын
Thanks man, i literally spent 3 hours on this and finally get after watching this
@BackToBackSWE4 жыл бұрын
excellent!
@LetsBeHuman5 жыл бұрын
@10:42 - Anytime we interact with the node, it moves to the front of the list. So, lets say we are going to update (that is, put( ) ) 4,10 as 4,20. Shouldn't it take O(n) to traverse the doubly linked list and find where 4 is? each time when we update an existing item in the list, what is the big O for searching that element? By the way, you are welcome to our home for delicious food.
@BackToBackSWE5 жыл бұрын
Hahahahahahahaha. Thanks for the offer. And no, access is O(1). We have a hashtable mapping to the memory address of each node. This costs us more space (excluding the list itself) but that is fine since it improves access time.
@xxiinsanexx3 жыл бұрын
very very well done. explanations on point. i was asked this question during an interview. got hash table but never remembered doubly linked list. now im quite sure im going to remember it for life. thanks once again mate!
@lings6285 жыл бұрын
Your channel is brilliant. I love it so much that I told all my friends about this channel. The clarity in your explanation filled with the energy and passion to teach is just fantastic 🙌
@BackToBackSWE5 жыл бұрын
thanks
@paulonteri4 жыл бұрын
The Greatest Explanation i've found... Please do more leeetcode.
@BackToBackSWE4 жыл бұрын
thx
@1point0tennis5 жыл бұрын
I kept getting stuck on how the doubly linked list removal would be O(n) then it clicked when you helped me realize the HashTable value points to the nodes themselves.
@BackToBackSWE5 жыл бұрын
yeah, the nodes have unique representations in memory and the hashtable maps those memory addresses.
@aayushvrshney4 жыл бұрын
Best LRU cache explanation on whole KZbin!
@BackToBackSWE4 жыл бұрын
thanks
@keshavrastogi50055 жыл бұрын
I have not seen such a great explanation and code. You are just awesome man. God bless you!
@BackToBackSWE5 жыл бұрын
thanks, if you liked this join our class, I'll be doing more explanations like this there
@Ana-vx5vx4 жыл бұрын
You teach better than my professor. Thanks
@BackToBackSWE4 жыл бұрын
ye
@sagarrajput71724 жыл бұрын
You are really good at what you do. It is rare to find genuine smartness and passion in same place. You should be proud of yourself. And yes humour makes it good too.🔥
@BackToBackSWE4 жыл бұрын
thx
@kamaboko15 жыл бұрын
Dude, you're a rock star. An explanation that made sense.
@BackToBackSWE5 жыл бұрын
nice
@airysm5 жыл бұрын
Thank u for making this question seem way less scary lol
@BackToBackSWE5 жыл бұрын
you are awesome.
@manishasharma28635 жыл бұрын
I am your Fan! No one can explain this with such simplicity. Thanks a ton! :)
@BackToBackSWE5 жыл бұрын
sure
@anssha26435 жыл бұрын
You are the best at what you are doing. Love the way you explain and makes things so easy. Its kind of motivating to me. Looking forward to more of your videos. God bless you.
@BackToBackSWE5 жыл бұрын
Thanks
@ananyaashrivastava27834 жыл бұрын
Wow ! You made the Question little easy to me ,thanks.
@BackToBackSWE4 жыл бұрын
great to hear
@jkmaksy4 жыл бұрын
Jeez, having MS interview in two days and then this video comes up :)
@BackToBackSWE4 жыл бұрын
lol, a prophecy it is
@DennisSmdFreefightTrainer4 жыл бұрын
How did you prepare for your MS interview when you didn't even know this problem?
@lugiadark213 жыл бұрын
Bro your channel is underrated, your explanations are the best
@perlaz11665 жыл бұрын
The opening is really cute!
@BackToBackSWE5 жыл бұрын
thnaks? lol, this was way back when no one watched this channel
@yasmineelezaby51972 жыл бұрын
WOW! that's the most clear and easy explanation for this problem. Thanks!
@cambeeler63745 жыл бұрын
Thank you! The way you break-down the problem, and then explain your thinking, really helps me to identify the pattern and approach to thinking around the problem for myself. I really appreciate your investment of time and energy !
@BackToBackSWE5 жыл бұрын
sure
@JoeWong815 жыл бұрын
I like your yelling bro it prevents me from falling asleep. nice explanation too
@BackToBackSWE5 жыл бұрын
hahahaha ok
@FrootNinja5 жыл бұрын
yea it really does help
@BackToBackSWE5 жыл бұрын
@@FrootNinja haha ok
@keshavsethi16104 жыл бұрын
thanks, man one of the neatest and most crisp explanation's I have heard
@BackToBackSWE4 жыл бұрын
sure
@seymour_videos3 жыл бұрын
i legit love his videos because of his sheer excitement and enthusiasm
@riskyferyansyahpribadi69843 жыл бұрын
a very detailed explanation and easy to understand, thank you Back to Back SWE
@BurhanWani15 жыл бұрын
Really liked your explanation. It might have also helped to explain how the hash table stores the address (or the objects in case of Object Oriented languages) of each node corresponding to a key. Good stuff overall.
@BackToBackSWE5 жыл бұрын
yep
@FrootNinja5 жыл бұрын
first video watched, the fact you left it at sooo i'm hungry then left was dope. smashed that like button and subbed
@BackToBackSWE5 жыл бұрын
hha thx
@poojaguru25165 жыл бұрын
Please make more videos Ben coz I'm just surviving by learning through Your videos!! Best explanation :) All of your videos are great! You are an inspiration :) keep doing more videos !! Thanks a ton!
@BackToBackSWE5 жыл бұрын
haha nice. I'm starting a class soon. I'll be making 3-4 vids a day w/ Chris Jereza. It'll be good.
@poojaguru25165 жыл бұрын
Waiting 😋😋
@BackToBackSWE5 жыл бұрын
@@poojaguru2516 haha
@bostonlights27494 жыл бұрын
Can we just give a shout-out to the awesome intro
@BackToBackSWE4 жыл бұрын
lol sorry - no one watched back then
@madhurapattekar58155 жыл бұрын
Very nice video. Please do more videos on LeetCode Questions. It will be helpful. Thanks!!
@BackToBackSWE5 жыл бұрын
Yeah, I have 250 scheduled as of now. Will take me over a year to do but we will see how far I get.
@wawwaw70634 жыл бұрын
thank you for your video, I came across this problem today and I had no idea how to implement O(1) put method until I see this
@BackToBackSWE4 жыл бұрын
sure
@TheRadistOne4 жыл бұрын
Thank you, my guy! This was so clear & I love the ENERGY!
@BackToBackSWE4 жыл бұрын
thanks
@ganeshchandrameesala2573 жыл бұрын
@@BackToBackSWE where is the code, I couldn't find it in the description
@karankanojiya76724 жыл бұрын
Teaching is an art, certainly mastered by this man! Respect++
@BackToBackSWE4 жыл бұрын
thx
@方宇凡-g4d5 жыл бұрын
Your videos are always the best, so clear, thank you~!
@BackToBackSWE5 жыл бұрын
sure
@doruwyl5 жыл бұрын
I appreciate a lot your dedication for explaining things to the other people. Well done!
@BackToBackSWE5 жыл бұрын
thanks
@shantanushende63 жыл бұрын
8:40 explained why the left has the LRU and why the right has MRU. Said it before saying it again, legend!!
@shilinwang29582 жыл бұрын
hash table & singly linked list! Thank you, the explanation is really clear.
@mrthelovepanda5 жыл бұрын
You can remove a node from a singly linked list in constant time. void RemoveNode (Node N){ N.data = N.next.data; N.next = N.next.next; } Great video, though. Helped a lot.
@BackToBackSWE5 жыл бұрын
yeah
@miry_sof5 жыл бұрын
Can you remove the last item?
@MrFTW10015 жыл бұрын
But isn’t searching for the item not constant time ?
@BackToBackSWE5 жыл бұрын
@@miry_sof yeah
@BackToBackSWE5 жыл бұрын
@@MrFTW1001searching would be O(n) time but if we over-write the node being deleted it can be done in O(1) time even for a single linked list. I'll cover that on the site I'm making: twitter.com/thebigoguide I didn't consider this when I made this video months ago
@FrootNinja5 жыл бұрын
Your channel should have subs like josh fluke, tech lead, joma tech & cs dojo. You're amazing bro! like keep this format up please!
@BackToBackSWE5 жыл бұрын
ok
@ravikanthreddy895 жыл бұрын
insane energy levels !! and nice editing/tranisitions in the algo tracing out. Liked it.
@BackToBackSWE5 жыл бұрын
I had a bad mic, sorry
@ashleylove3084 жыл бұрын
This intro is everything...Nice walkthrough += entertaining
@BackToBackSWE4 жыл бұрын
ye
@ayushagrawal2584 жыл бұрын
Man you made this problem look so easy 🔥🔥
@BackToBackSWE4 жыл бұрын
thanks
@yuxinshi20985 жыл бұрын
Really helpful! You made this question simple and easier to understand, love the graph!
@BackToBackSWE5 жыл бұрын
Everything can be made clear with the proper instruction. I am trying to get better at teaching daily. It is very hard. Thank you for watching.
@xavierelon2 жыл бұрын
That intro had me dying 🤣 thanks for the amazing content as always
@nagamass5 жыл бұрын
Excellent video. I think, if reached capacity, we need to delete node first before adding. This way, we won't be out of space allocated for Cache
@BackToBackSWE5 жыл бұрын
If we reach capacity we eject the LRU item right? Why the first node if that is where the freshest item is inserted?
@nagamass5 жыл бұрын
@@BackToBackSWE I feel, we can do eviction before adding new node if we reach limit. let say, limit 4, before adding 5th node, we can do eviction and add the node. but in video, we are adding 5th node then deleting node.
@nagamass5 жыл бұрын
@@BackToBackSWE I feel, we can do eviction before adding new node if we reach limit. let say, limit 4, before adding 5th node, we can do eviction and add the node. but in video, we are adding 5th node then deleting node.
@BackToBackSWE5 жыл бұрын
@@nagamass We can do it in either order, the final state after removal is the same.
@sarahm5750 Жыл бұрын
Great video and insightful, also love your energy!!
@marlegagaming12745 жыл бұрын
You deserve more subscribers
@BackToBackSWE5 жыл бұрын
Thanks!
@ReneeSLiu-zx5tj5 жыл бұрын
I appreciate your thought-process sharing!
@BackToBackSWE5 жыл бұрын
sure
@AShahabov3 жыл бұрын
Awesome LRU explanation!
@john_rambo_270985 жыл бұрын
I LOVED the starting...
@BackToBackSWE5 жыл бұрын
haha I remember it
@pulkitagrawal50544 жыл бұрын
Wonderful Explanation !! Great work Dude !! Keep making such videos !
@BackToBackSWE4 жыл бұрын
thx
@krishnapurohit34945 жыл бұрын
You can delete in O(1) from singly linked list given the pointer to delete.
@BackToBackSWE5 жыл бұрын
yeah
@helloworld44755 жыл бұрын
Thanks, you have very good whiteboard skills.
@BackToBackSWE5 жыл бұрын
sure
@satheshbm925 жыл бұрын
Man you are the killer. Binge watching all videos :)
@BackToBackSWE5 жыл бұрын
Haha. Excellent. Learn. Grow. And dominate the interview.
@margeshpatel84564 жыл бұрын
Like the energy and enthusiasm for teaching. Keep up :)
@BackToBackSWE4 жыл бұрын
thx
@architgoyal23365 жыл бұрын
I am new to your channel and this is a great channel. Loved the enthusiasm. Subscribed
@BackToBackSWE5 жыл бұрын
thanks
@r1jsheth5 жыл бұрын
This was one hell of explanation! Many thanks.
@BackToBackSWE5 жыл бұрын
Haha sure
@humansofcrypto97465 жыл бұрын
You can delete an item in a singly ll without knowing its previous node as well, just overwrite the data and the ptr from the next node and delete it.
@BackToBackSWE5 жыл бұрын
Yeah that is true, there is just an edge case if you are deleting the last ndoe - correct? I haven't deeply thought about this.
@vijayj19974 жыл бұрын
Best explanation than many other youtubers If it possible can you explain manacher's algorithm ?
@BackToBackSWE4 жыл бұрын
yes
@tashifhoda24144 жыл бұрын
Really nice explanation. I was able to implement it with STL on my own!
@BackToBackSWE4 жыл бұрын
great!!
@ok.google3 жыл бұрын
Glad I've guessed implementation right
@Adam-tz6gk9 күн бұрын
Outstanding explanation thank you so much
@Siddarthathota5 жыл бұрын
Can you also create a video on HashMap Implementation. This video about LRU cache is one of the best explanation I came across.
@BackToBackSWE5 жыл бұрын
Yep, I had this in the pipeline until I started working on the website I'm making rn for the channel...you'll see it in 1-2 months
@sergebyusajabo21383 жыл бұрын
This is a really good explanation. Thank you.
@sumanthm46053 жыл бұрын
I couldn't find the code in description.. Can somebody tell me where it is.. It's a bit urgent.
@xiaoruizhou6945 жыл бұрын
very clear explanation! Thank you sir.
@BackToBackSWE5 жыл бұрын
ye
@anupkulkarni17035 жыл бұрын
Good Job Mate! Subscribed to the channel!
@BackToBackSWE5 жыл бұрын
love.
@unanimous8510 Жыл бұрын
Once I watched the first 15 secs of this video I immediately smashed the like button lol
@LipsaSenapati3 жыл бұрын
Thank you for the awesome explanation! Very energetic! Request: It will be very very helpful if you upload a video for the Priority Expiry Cache with python code (probably using 2 heaps and 2 hashmaps works well but I am trying to use an OrderedDict for better performance likely improvement from O(log n)->O(1))
@vm16625 жыл бұрын
Great explanation! Also, the code is very clear. Really appreciate it. :)
@BackToBackSWE5 жыл бұрын
sure
@alvintan49005 жыл бұрын
When you use the get function such as get(3) in this video, i understand the 'get' lookup uses the hashtable which is O(1) to retrieve. However, isnt it worst case O(n) to go through the doubly linked list to find the value of 3 in the DLL because you need to traverse through the nodes and thus making overall time complexity of the retrieval to be O(n)?
@BackToBackSWE5 жыл бұрын
the hashtable will give us O(1) lookup
@alvintan49005 жыл бұрын
@@BackToBackSWE in this same process, you have to move the 3 key into the head in the DLL, which is what I am referring to the time complexity
@BackToBackSWE5 жыл бұрын
@@alvintan4900 Ah, yes we have reference to the head node so we can grab that reference and wire the touched node to the front in O(1) time
@BackToBackSWE5 жыл бұрын
@Lisa Jones I did dang chill 😨😨
@randomuser664385 жыл бұрын
@@BackToBackSWE You still didn't answer the question. If you want the least recently used value, you'll have to traverse the whole DLL to get the hash-table reference, regardless of bringing the node to the front afterwards. Doesn't this make the retrieval time O(n)?
@hz36003 жыл бұрын
love your energy, very engaging, and this was a very useful video. Thank you so much!
@amarajavijayakumar9382 жыл бұрын
are u able to see the code on the description?
@MrLazini Жыл бұрын
Very clear explanation, much appreciated :)
@BackToBackSWE Жыл бұрын
Thank you! Please enjoy a special code from us - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=MrLazini 🎉
@laminendy4 жыл бұрын
That's an awesome explanation! Thank you!
@BackToBackSWE4 жыл бұрын
sure!
@rishabkumar49404 жыл бұрын
Thanks for explaining it so clearly, I was having a tough time understanding it as its solution is locked on Leetcode😅
@BackToBackSWE4 жыл бұрын
great
@200415374 жыл бұрын
easy to understand. well done!!!
@BackToBackSWE4 жыл бұрын
thx
@kumarprateek12795 жыл бұрын
Really good implementation and loved your thought process.
@BackToBackSWE5 жыл бұрын
thx
@zummotv10135 жыл бұрын
DataStructure and Algo group on WhatsApp.Please Join chat.whatsapp.com/GKVxU5dvU1e3v7h9ctDpXn
@kishantiwari32214 жыл бұрын
Great Explanation...Thankl you
@BackToBackSWE4 жыл бұрын
sure
@asishsandhya5 жыл бұрын
Great video dude..You made the problem so simpler. Thanks for that. I just subscribed to your channel.. yayyy
@BackToBackSWE5 жыл бұрын
sure, welcome to the party
@Nampjg4 жыл бұрын
Loved your energy man!
@BackToBackSWE4 жыл бұрын
thanks
@quentinlassalle13214 жыл бұрын
Awesome explanation, many thanks!
@BackToBackSWE4 жыл бұрын
sure.
@sihanyang83933 жыл бұрын
Where is the code plz? I didn't find it in the description. Thanks for the excellent video!
@lakshitaagarwal4003 жыл бұрын
Awesome Explanation......... Can you please provide the code also as you said in the video.....I didnt find the code in description.