All Problems

Problem title

Difficulty

Avg time to solve

Maze with N doors and 1 Key

Moderate

15 mins

Dice Throws

Hard

35 mins

Mean Median Mode

Easy

10 mins

Sum Tree

Moderate

29 mins

Leaves One Level Apart

Moderate

40 mins

Divide Linked List In Two

Easy

20 mins

Football Game

Easy

20 mins

Distinct Left

Moderate

20 mins

Longest Subarray Zero Sum

Moderate

18 mins

Gas Tank

Moderate

20 mins

Problem

Submissions

5

Avg. time to solve

20 min

Success Rate

70%

Problem Statement

```
For the given array arr = [5, 3, 2, 3, 4, 3] and K = 3.
Output = 2
We have to delete three maximum elements, i.e. 5, 4, and 3. So, the array after the deletions contains 2, 3, and 3. Now, we only have two distinct elements left in the array (2 and 3).
```

```
The first line of input contains an integer 'T' representing the number of test cases or queries to be processed. Then the test case follows.
The first line of each test case contains two single space-separated integers 'N' and 'K' representing the size of the array/list and the given integer respectively.
The second line of each test case contains 'N' single space-separated integers representing the array/list elements.
```

```
For each test case, print a single integer, i.e. the number of distinct elements left in the array/list.
Print output of each test case in a separate line.
```

```
You are not required to print the output, it has already been taken care of. Just implement the function.
```

```
1 <= T <= 10
1 <= N <= 10^4
1 <= K <= N
1 <= ARR[i] <= 10^9
Time Limit: 1 sec
```

```
2
5 3
1 3 2 2 4
4 2
10 4 8 5
```

```
2
2
```

```
For the first test case we have 4, 3 and 2 as three maximum elements. After deleting these three elements, we are left with array [1, 2]. Hence, we are left with two distinct elements in the array.
For the second test case we have 10 and 8 as two maximum elements. After deleting these three elements, we are left with array [4, 5]. Hence, we are left with two distinct elements in the array.
```

```
1
8 5
4 7 4 6 7 1 2 4
```

```
3
```

Java (SE 1.8)

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 Theme

Solution submission not allowed

Save Code

Reset Code