Skip to content

Bug Report for lru-cache #4939

@deepsh4h

Description

@deepsh4h

Bug Report for https://neetcode.io/problems/lru-cache

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

Explanation:
LRUCache lRUCache = new LRUCache(2);
lRUCache.put(1, 10); // cache: {1=10}
lRUCache.get(1); // return 10
lRUCache.put(2, 20); // cache: {1=10, 2=20}
lRUCache.put(3, 30); // cache: {2=20, 3=30}, key=1 was evicted <--- key=2 should have be evicted as it was LRU and not key=1
lRUCache.get(2); // returns 20
lRUCache.get(1); // return -1 (not found)

Ref: https://leetcode.com/problems/lru-cache/description/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions