Company: OYO_SDE intern_Oncampus_24june
Difficulty: medium
Memory Buffer with Access-Based Replacement Problem Description A memory buffer is a small storage system that keeps key-value pairs and uses a replacement rule to stay within its memory limit. This buffer follows the Least Frequently Used (LFU) rule: when it is full and a new key must be stored, it removes the stored key with the lowest access frequency. The buffer can hold at most N keys and starts empty. You are given Q operations, each written as three integers type key value : Type 1 ( 1 key -1 ): read the value stored for key . If key is not in the buffer, the answer is -1 . A read does not change the access frequency of the key. Type 2 ( 2 key value ): write value for key . If key is already in the buffer, replace its value and increase its access frequency by 1. Nothing is removed. If key is not in the buffer, insert it with access frequency 1. If the buffer already holds N keys, first remove the key with the lowest access frequency. If two or more keys share that lowest freque