lru-cache:

LRU Cache Miss Count

Solution public class CacheMiss { public int missCount(int[] array, int size) { if (array == null) return 0; List<Integer> cache = new LinkedList<>(); int count = 0; for (int i = 0; i < array.length; i++) { if (cache.contains(array[i])) { cache.remove(new Integer(array[i])); } else { count++; if (size == cache.size()) cache.remove(0); } cache.add(array[i]); } return count; } }

by lek tin in "algorithm" access_time 1-min read

LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.

by lek tin in "algorithm" access_time 4-min read