Skip to content

Conversation

sachiny123
Copy link

This PR implements the Least Recently Used (LRU) Cache data structure in C++ using
unordered_map and list for efficient O(1) access and updates.

Features:

  • get(key): Returns the value of the key if it exists, else returns -1.
  • put(key, value): Inserts a new key-value pair or updates an existing key.
    If the cache exceeds its capacity, the least recently used item is removed.
  • Efficient O(1) time complexity for both get and put operations.
  • Includes example usage in main() demonstrating functionality.

This implementation is practical for interview preparation and real-world applications
where caching with eviction policy is required.

Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No code => no bugs 😄

Copy link
Contributor

@mindaugl mindaugl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is truly a perfect implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants