P19850 [GeeksforGeeks] Maximum distinct elements after removing k elements5906
普及-
题目描述

Given an array containing N elements. The task is to find the maximum number of distinct elements after removing K elements from the array.
Example 1:
Input : Arr[] = {5, 7, 5, 5, 1, 2, 2}, K = 3
Output : 4
Explanation:
Remove 2 occurrences of element 5 and
1 occurrence of element 2.
Example 2:
Input : Arr[] = {1, 2, 3, 4, 5, 6, 7}, K = 5
Output : 2
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function maxDistinctNum() that takes an array (arr), sizeOfArray (n), integer value K, and return the maximum distinct elements after removing K elements. The driver code takes care of the printing.
Expected Time Complexity: O(K*logD) where D is the number of distinct elements in the given array.
Expected Auxiliary Space: O(N).

Constraints:
1 ≤ K ≤ N ≤ 10^{6}
1 ≤ A[i] ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
Arr[] = {5, 7, 5, 5, 1, 2, 2}, K = 3
样例输出
4