I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!
\
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.HashMap; | |
| public class LRUCacheWith2DataStructures { | |
| // Doubly Linked List Node | |
| class CacheNode { | |
| String key; | |
| String val; | |
| CacheNode next; | |
| CacheNode prev; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.LinkedHashMap; | |
| import java.util.Map; | |
| class LRUCache extends LinkedHashMap<String, String> { | |
| private int capacity; | |
| public LRUCache(int capacity) { | |
| super(capacity, 0.75F, true); | |
| this.capacity = capacity; |