🎁 Exclusive Offer! Join our Telegram Channel to get **special discounts** and updates! 🚀

🚀 Struggling with coding interviews? We've got you covered! 💡 Practice real questions, sharpen your skills, and land your dream job! 🎯
Question 48 - 100% Working Solution | Buy Now

Description

10 Live
Question 2 Implement a Least Frequently Used (LFU) cache data structure of size cacheSize that handles two types of queries: GET and PUT. A GET query attempts to retrieve the value of a given key. If the key is present in the cache, it is returned. Otherwise, it returns -1. A PUT query updates or inserts a key-value pair into the cache. When the cache is full, the least frequently used key is removed to accommodate the new key-value pair. If there is a tie in the frequency of keys, then the least recently used key is removed. Return an array of integers where each i-th element is the answer for the i-th GET query. Example Suppose cacheSize = 1 q = 5 queries = ["PUT 1 1", "PUT 2 2", "GET 1"] Only cacheSize = 1 element is stored in the cache.

Asked in: ShareChat

Image of the Question

Question Image

All Testcases Passed ✔



Passcode Image

Solution


Please login to view the solution