Maximum distinct elements after removing K elements
Submissions: 2213   Accuracy:

35.91%

  Difficulty: Easy   Marks: 2

Given an array containing N elements. The task is to find maximum number of distinct elements after removing K elements from the array.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains two Integers N and K and the second line contains N space separated elements.

Output:
For each test case, print the maximum distinct elements after removing K elements in new line.

Constraints:
1<=T<=100
1<=K<=N<=106

1<=A[i]<=105

Example:
Input:

2
7 3
5 7 5 5 1 2 2
7 5
1 2 3 4 5 6 7
Output:
4
2

Explanation:

Input : A[] = {5, 7, 5, 5, 1, 2, 2}, K = 3
Output : 4
Remove 2 occurrences of element 5 and
1 occurrence of element 2.

** For More Input/Output Examples Use 'Expected Output' option **

Author: arun03


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



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

to report an issue on this page.