Prototype: TouchOrder(keys []string,key string) []string returns a new oldest-to-newest slice, moving an existing key to end or appending new. Inputs are valid distinct nonempty keys.

Final: NewLRUCache(capacity int) (*LRUCache,error) requires nonnegative capacity. Put(key string,value int) error validates nonempty key, inserts/updates and refreshes, then evicts least recent if necessary; capacity zero is no-op after validation. Get(key string,fallback *int) (*int,error) validates key, refreshes a hit and returns detached value; miss returns the supplied fallback pointer unchanged (including identity), without recency change. Delete(key) (bool,error) validates and removes once. Items() []CacheItem returns detached least-to-most order. Negative values and zero valid; target O(1) final operations with a map and linked order.

All identifiers and strings compare exactly and case-sensitively. Numeric inputs are typed int; booleans cannot be passed as amounts. Arithmetic and logical timestamps fit int. All supplied collection inputs that are retained must be copied. Every collection or pointer snapshot must be detached; separate service instances own independent state. A nil pointer or nil optional slice denotes absence, while an ordinary empty result collection is nonnil. Invalid calls leave state unchanged unless the contract explicitly accepts time and expires state on a valid unsuccessful call. The exported signatures in exercise.go are the API specification.

Edit exercise.go; retain the public types and signatures. prototype and final are separate stages. The executable tests recover panics as failures, report named checks, and exit nonzero on any failure. A successful run must execute at least one check. Tests use logical time or explicit synchronization where relevant.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.