Cache eviction misses
Your task
A build farm replays a recorded fetch log through a local artifact cache that holds at most slot_count artifacts and starts empty. requests[i] is the artifact fetched at step i. Fetching an artifact that is already resident costs nothing. Fetching an absent one is a miss: it gets loaded, and if every slot is already full then exactly one resident artifact is dropped to make room. Because the entire log was recorded before this replay begins, you may choose each drop knowing every fetch still to come. Return the fewest misses the replay can end with. slot_count may be 0, in which case every fetch misses, and the log may be empty. Dropping whichever artifact went unused the longest is not always the fewest.
Examples
fewest_fetch_misses(requests: list[int], slot_count: int) -> intExample 1
Input
fewest_fetch_misses([1, 2, 3, 1, 2, 3], 2)Output
4Example 2
Input
fewest_fetch_misses([4, 4, 4, 4], 1)Output
1