{"id":5761,"date":"2026-02-24T03:46:57","date_gmt":"2026-02-24T03:46:57","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=5761"},"modified":"2026-02-24T03:46:57","modified_gmt":"2026-02-24T03:46:57","slug":"5761-2","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/5761-2\/","title":{"rendered":""},"content":{"rendered":"<p>import java.util.HashMap;<br \/>\nimport java.util.Map;<\/p>\n<p>public class LRUCache {<br \/>\n    static DLLNode head;<br \/>\n    static DLLNode tail;<br \/>\n    Map<Integer, DLLNode> hmDictionary = new HashMap();<\/p>\n<p>    public DLLNode searchCache(DLLNode dllNode){<br \/>\n        return hmDictionary.get(dllNode.val);<br \/>\n    }<\/p>\n<p>    \/\/Check if the cache size has been exhausted, if so remove the element from map<br \/>\n    public void addToCache(DLLNode dllNode){<br \/>\n        if(hmDictionary.get(dllNode.val) == null){<br \/>\n            hmDictionary.put(dllNode.val, dllNode);<br \/>\n        }else{<br \/>\n            dllNode.prev.next = dllNode.next;<br \/>\n            dllNode.next = LRUCache.tail;<br \/>\n            LRUCache.tail.prev = dllNode;<br \/>\n        }<\/p>\n<p>        if(hmDictionary)<br \/>\n    }<\/p>\n<p>    public void removeFromCache(DLLNode dllNode){<br \/>\n        if(hmDictionary.get(dllNode.val) != null){<br \/>\n            hmDictionary.remove(dllNode.val);<br \/>\n        }<br \/>\n    }<\/p>\n<p>}<br \/>\npublic class DLLNode {<br \/>\n    DLLNode prev;<br \/>\n    DLLNode next;<\/p>\n<p>    Integer val;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>import java.util.HashMap; import java.util.Map; public class LRUCache { static DLLNode head; static DLLNode tail; Map hmDictionary = new HashMap(); public DLLNode searchCache(DLLNode dllNode){ return hmDictionary.get(dllNode.val); } \/\/Check if the cache size has been exhausted, if so remove the element from map public void addToCache(DLLNode dllNode){ if(hmDictionary.get(dllNode.val) == null){ hmDictionary.put(dllNode.val, dllNode); }else{ dllNode.prev.next = dllNode.next; dllNode.next&hellip; <a href=\"https:\/\/codethataint.com\/blog\/5761-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5761","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=5761"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5761\/revisions"}],"predecessor-version":[{"id":5762,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5761\/revisions\/5762"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=5761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=5761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=5761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}