Find K Distinct Element Frequencies
Given a list of N integers, find the K-th largest frequency of elements in the list. If there are fewer than K distinct frequencies, output 0. The elements themselves can be positive, negative, or zero. The frequencies are the counts of how many times each distinct integer appears in the list.
Input
The first line contains two integers N and K. The second line contains N integers, the elements of the list.
Output
Print a single integer: the K-th largest frequency. If there are fewer than K distinct frequencies, print 0.
Constraints
1 <= N <= 200000, 1 <= K <= N. Each element value is between -10^9 and 10^9.
Example 1
10 3 1 1 2 2 2 3 3 4 5 5
2
Frequencies are: 1 (for 4, 5), 2 (for 3), 3 (for 2), 2 (for 1). Distinct frequencies are 1, 2, 3. Sorted descending: [3, 2, 1]. The 3rd largest frequency is 1.
Example 2
5 2 10 20 10 30 10
1
Frequencies are: 3 (for 10), 1 (for 20), 1 (for 30). Distinct frequencies are 3, 1. Sorted descending: [3, 1]. The 2nd largest frequency is 1.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
10 3 1 1 2 2 2 3 3 4 5 5
5 2 10 20 10 30 10