Given an integer array A of size N and a positive integer B. Find B numbers with most occurrences, i.e., the top B numbers having the maximum frequency.
If two numbers have the same frequency then the larger number should be given preference. The numbers should be displayed in decreasing order of their frequencies.
NOTE: It is assumed that the array consists of B numbers with most occurrences.
1 <= N <= 105
1 <= B <= N
1 <= A[i] <= 109
First argument is an integer array A.
Second argument is an integer B.
Return an integer array denoting the top B numbers having the maximum frequency.
A = [3, 1, 4, 4, 5] B = 2
A = [1, 1, 1, 4, 4] B = 2
Frequency of element 4 is 2 and all others element have frequency 1. First element will be 4 and second element will be 5 (Since it is largest among [1, 3, 5]).
Frequency of element 1 is 3 and element 4 have frequency 2. First element will be 1 and second element will be 4.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.