ShareChat Coding Question – Solved

7 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


Related Questions

| The supply chain manager at one of Amazon's warehouses is shipping the last con… |
| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |
| In this new stock prediction game launched on Amazon Games, Player 1 provides P… |
| Amazon operates numerous warehouses, with each warehouse holding inventory[i] u… |
| In Amazon's highly efficient logistics network, minimizing operational overhead… |