Track a least recently used cache · Compiler
Track a least recently used cache
Track keys in an initially empty cache. WRITE inserts a missing key or refreshes a present key as most recently used. READ refreshes a present key and does nothing on a miss. Before inserting into a full cache, remove its least recently used key. Report the keys removed this way.
- Input
- Line 1 contains the capacity (1 to 20) and the number of operations q (1 to 100). Each of the next q lines contains READ or WRITE followed by a space and a key of 1 to 12 lowercase ASCII letters.
- Output
- Print all evicted keys in chronological order on one line, separated by spaces. If there were no evictions, print NONE.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…