LRU Cache Implementation Design and implement a data structure for Least Recently Used (LRU) cache to support the following operations: 1. get(key) - Return the value of the key if the key exists in the cache, otherwise return -1. 2. put(key, value), Insert the value in the cache if the key is not already present or up...
read more
CodingNinjas
author
2y
Answer :Structure of an LRU Cache :1) In practice, LRU cache is a kind of Queue — if an element is reaccessed, it goes to the end of the eviction order.2) This queue will have a specific capacity as t...
see more
CodingNinjas
author
2y
Array Approach We will use an array of type Pair<key, value> to implement our LRU Cache where the larger the index is, the more recently the key is used. Means, the 0th index denotes the least r...
see more
CodingNinjas
author
2y
Using HahMap with Queue We will use two data structures to implement our LRU Cache. Queue<Node>: To store the nodes into cache where the least recently used key will be the head node and th...
see more
Add answer anonymously...
Top JPMorgan Chase & Co. Senior Software Engineer interview questions & answers
Popular interview questions of Senior Software Engineer
Top HR questions asked in JPMorgan Chase & Co. Senior Software Engineer
>
JPMorgan Chase & Co. Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app