Your question is Data Structures Coding Challenge. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
University of Michigan Canvas services may cache recently accessed course data, but the cache must evict the least recently used item when it reaches capacity. Implement an LRU cache that supports get and put operations efficiently.
Write lru_cache_operations(capacity, operations), where capacity is an integer and operations is a list of operations. Each operation is one of:
['get', key]: Return the value for key, or -1 if the key is absent. A successful get makes the key most recently used.['put', key, value]: Insert or update the key. The operation produces no output. An updated key becomes most recently used.Return a list containing the results of all get operations, in order. Use a hash map plus a doubly linked list so both operations run in constant time.
def lru_cache_operations(capacity, operations):