Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-199

Working Set Window Count

Problem

Compute the size of the working set after every reference.

references is the sequence of page references and window is the number of most recent references considered. After each reference, the working set is the set of distinct pages in the last window references (or all references so far when fewer exist).

Return the list of working set sizes.

Hint

The window slides forward by one reference at each step.

Test cases

case 1
in: [[1,2,1,3,4],3]
expected: [1,2,2,3,3]
case 2
in: [[1,1,1],2]
expected: [1,1,1]
case 3
in: [[],3]
expected: []
case 4
in: [[5,6],5]
expected: [1,2]
Starter codePython
def working_set_pages(references, window):
    # Your code here
    pass

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