CLOCK page cache

Write codeHard35 minOracle style

Your task

Simulate a page cache using the CLOCK (second-chance) eviction policy. The cache holds at most capacity pages arranged in a circular buffer with a clock hand that starts at slot 0. Each page has a reference bit. Process a list of page-id accesses. On access: if the page is resident it is a HIT and its reference bit is set to 1. On a miss, if there is a free slot the page is loaded there (ref bit 1) and the hand is unchanged; if the cache is full, advance the hand, repeatedly clearing ref bits of pages with bit 1 (giving second chances) until a page with bit 0 is found, evict it, load the new page in its slot with ref bit 1, and leave the hand pointing one past that slot. Return the total number of hits. capacity >= 1; <= 10^5 accesses.

Examples

clock_cache_hits(capacity: int, accesses: list[int]) -> int
Example 1
Inputclock_cache_hits(2, [1, 2, 1, 3, 2])
Output2