1
2
3
4
5
6
Use the "Verify Solution" button to get AI feedback on your Kotlin code.
Implement a thread-safe, fixed-size Least Recently Used (LRU) cache in Kotlin. The cache should support get(key) and put(key, value) operations. When the cache reaches its capacity, the least recently used item should be evicted to make space for new items. All operations must be thread-safe.
Requirements:
capacity.get(key): Returns the value associated with key if it exists. Accessing an item makes it the most recently used.put(key, value): Adds or updates an item. If the key already exists, its value should be updated, and it becomes the most recently used. If adding a new item exceeds capacity, the least recently used item must be evicted.get, put) must be thread-safe.