Prompt
Implement an LRU (least-recently-used) cache in Python.
Provide a class `LRUCache` with:
- `LRUCache(capacity)` — fixed positive integer capacity.
- `get(key)` — return the value, or `-1` if the key is absent. A successful `get` counts as a use.
- `put(key, value)` — insert/update. A `put` counts as a use. When over capacity, evict the least-recently-used key.
Put the class in a single Python code block. It will be imported as `from solution import LRUCache`.when to use it
Community prompt sourced from the open-source GitHub repo Green-PT/honey-for-devs (MIT). A "Prompt" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
codingcommunitydeveloper
source
Green-PT/honey-for-devs · MIT
more in Coding
Coding✓ tested
Senior code review (strict mode)
senior staff engineer running a merciless but fair review
Coding✓ tested
Debug by hypothesis, not by guessing
debugging partner who forms theories before touching code
Coding✓ tested
Generate tests from described behavior
test engineer who writes tests that would actually catch regressions