BETA

Submissions : 370 Accuracy :

23.51

Page Faults in LRU
       

In operating systems that use paging for memory management, page replacement algorithm are needed to decide which page needs to be replaced when new page comes in. Whenever a new page is referred and is not present in memory, page fault occurs and Operating System replaces one of the existing pages with newly needed page.
Given a sequence of pages and memory capacity, your task is to find the number of page faluts using Least Recently Used (LRU) Algorithm .

Input:
The first line of input contains an integer T denoting the number of test cases. Each test case contains number of pages n and next line contains space seaprated sequence of pages. The following line consist of the capacity of the memory.

Output:
Output the number of page faults.

Constraints:
1<=T<=100
1<=n<=1000
4<=capacity<=100

Example:
Input:
2
9
5 0 1 3 2 4 1 0 5
4
8
3 1 0 2 5 4 1 2
4
Output:
8
7

**For More Examples Use Expected Output**


Contributor: Shubham Chaudhary

Set Default Code

					   
Result:
It is recommended to test your code before clicking 'Submit' button!



                   



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.