Challenge Information

Title : LRU Algorithm
Difficulty : Medium
Solutions : 7
Maximum Score : 100
Completed by You: No
Description :

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

Write a function solve that have the following parameter(s):
1.) a = integers array indicating pages
2.) b = integer indicating memory capacity

Example
Input:
a = [1, 0, 4, 3, 7, 6]
b = 3
Output:
6

Explanation
Memory allocated with 3 pages 1, 0, 4: page fault = 3
Page number 3 is required, replaces LRU 1: page fault = 3 + 1 = 4
Page number 7 is required, replaces LRU 0: page fault = 4 + 1 = 5
Page number 6 is required which replaces LRU 4: page fault = 5 + 1 = 6
Constraints

Judocode