At Nimbus Storage, block requests are processed in order, but the retrieval layer can prefetch a limited number of distinct blocks at a time. Given a sequence of requested block IDs and a cache capacity k, write a function that returns the length of the longest contiguous request segment that can be served using at most k distinct block IDs.
This models optimizing retrieval by maximizing the largest request window that fits within the storage system's active block set.
requests: a list of integers representing block IDsk: an integer representing the maximum number of distinct block IDs allowed in the active retrieval windowk distinct valuesdef longest_retrieval_window(requests, k):