Frequency

0

0 votes
Medium
Problem

You are given an array of n numbers .You have to find the xth highest occuring element. If there exists a situation where there are 2 or more numbers having the same frequency then the one with the minimum value is returned as output.

Input :

1st line holds the length of the array(N).

2nd line holds the N array elements Ai separated by space.

3rd line holds the value of X.

Output :

The xth highest occuring array element if such is there or else 0.

CONSTRAINT :

0<=N<=103

0<=Ai<=105

0<=X<=100

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here there are 3 numbers 1,2 and 3 with frequency 3,2 and 2. Then the second highest frequency number is asked which is 2(2<3), the output. If the 3rd highest would have been asked then the output would have been 0.

Editor Image

?