Skip to content
DeepForgeby svx
All problems
MediumData Structuresds-277

LRU vs LFU Hit Count Comparison

Problem

Compare LRU and LFU hit counts on the same page reference string.

pages is the reference sequence and capacity is the number of frames. LRU evicts the least recently used page; LFU evicts the least frequently used page, breaking ties by least recent use.

Return [lru_hits, lfu_hits].

Hint

LFU ties are broken by recency so the eviction choice stays deterministic.

Test cases

case 1
in: [[1,2,3,1,2,4,1,2],3]
expected: [4,4]
case 2
in: [[1,1],1]
expected: [1,1]
case 3
in: [[1,2,1],1]
expected: [0,0]
case 4
in: [[7],1]
expected: [0,0]
Starter codePython
def lru_vs_lfu(pages, capacity):
    # Your code here
    pass

4 test cases · run your code against them in the editor