All problems
Copy-on-Write Page Fault Count
Problem
Count copy-on-write faults after a process fork.
fork_pages is the set of pages shared by parent and child at fork time, operations contains "read" or "write", and pages gives the page referenced. A write to a shared page faults only the first time, because it then becomes private; reads and non-shared writes never cause a copy fault.
Return the number of copy-on-write faults.
Hint
Once a shared page is copied it is private, so later writes do not fault.
Test cases
case 1
in: [[1,2],["read","write","write","write"],[1,1,1,2]]
expected: 2
case 2
in: [[1],["write","write"],[1,1]]
expected: 1
case 3
in: [[],["write"],[5]]
expected: 0
case 4
in: [[1,2],["read","read"],[1,2]]
expected: 0
case 5
in: [[1],["write"],[2]]
expected: 0
Starter codePython
def cow_page_faults(fork_pages, operations, pages):
# Your code here
pass5 test cases · run your code against them in the editor