Login

All Problems

Problem title

Difficulty

Avg time to solve

Berth Of Railway Seat Number

Easy

15 mins

Conversion

Easy

20 mins

Page Faults

Moderate

30 mins

Quadratic Probing in Hashing

Easy

25 mins

Maximum Performance of a Team

Moderate

15 mins

Dijkstra's shortest path

Easy

--

Find the maximum element in the array after update operations.

Moderate

15 mins

Magic Park

Hard

40 mins

Huffman Coding

Moderate

25 mins

Count of paths

Hard

50 mins

Problem

Submissions

0

Avg. time to solve

30 min

Success Rate

70%

Problem Statement

```
First-line contains an integer ‘T’, denoting the number of Test cases.
For each Test case:
The first line contains two space-separated integers, ‘N’ and ‘C’.
The following line contains the array ‘Pages’ of the length ‘N’, denoting the sequences of the page.
```

```
For each test case, print a single integer denoting the total number of page faults.
```

```
You don’t need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= ‘T’ <= 5
1 <= ‘N’ <= 10^5
0 <= ‘C’ <= 10^5
1 <= Pages[i] <= ‘N’, for 1 <= i <= ‘N’
Time Limit: 1 sec
```

```
2
4 3
1 3 2 1
5 3
1 2 3 4 3
```

```
3
4
```

```
For test case 1:
Memory allocated with 3 pages, {1, 3, 2}. Hence total page faults = 3.
Page number ‘1’ is required, which is already present. Hence total page faults = 3 + 0 = 3.
For test case 2:
Memory allocated with 3 pages, {1, 2, 3}. Hence total page faults = 3.
Page number ‘4’ is required, So we replace LRU page ‘1’. Hence total page faults = 3 + 1 = 4.
Page number ‘3’ is required, which is already present. Hence total page faults = 4 + 0 = 4.
```

```
2
9 4
5 6 1 3 2 4 1 6 5
7 3
1 2 1 4 2 3 5
```

```
8
5
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code