Panda Guru LogoPanda
Guru

PhonePe | Machine Coding | Nov 2024 | SDE-3

Round 1

Questions: Your task is to design and implement an in-memory caching system that is capable of storing and retrieving key-value pairs efficiently. The cache should have a capacity limit, after which the items should be evicted using an eviction policy to make space for new items. The cache should provide the following operations:

Additionally, the cache should support several configuration options, such as:

Bonus:

  1. Sync/ Asynchronous loading (cache creation)
  2. Implement other expiration strategy
  3. Implement refresh strategies.

Test Cases:

Candidate's Approach

The candidate designed an in-memory caching system using a combination of a hash map for O(1) access time and a doubly linked list to maintain the order of usage for eviction purposes. The implementation included methods for adding, retrieving, and removing items, as well as handling expiration strategies and capacity limits. The candidate also considered edge cases such as handling non-existent keys and ensuring that the eviction policy worked correctly when the cache reached its capacity.

Interviewer's Feedback

The interviewer appreciated the candidate's structured approach to the problem and the clarity of the implementation. They suggested considering additional edge cases and optimizing the eviction strategy further. Overall, the candidate demonstrated a solid understanding of caching mechanisms.