X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Numbers with prime frequencies greater than or equal to k
Easy Accuracy: 32.2% Submissions: 351 Points: 2

You are given an array of size N. You need to find elements which appear prime number of times in the array with minimum K frequency (frequency >= K).

Example 1:

​Input : 
N = 13, K = 2
arr[ ] = {11, 11, 11, 23, 11, 37, 51, 
          37, 37, 51, 51, 51, 51}
Output : 37 51
Explanation:
11's count is 4, 23 count 1, 37 count 3, 
51 count 5. 37 and 51 are two number that 
appear prime number of time and frequencies 
greater than or equal to K=2.

Example 2:

Input : arr[ ] = {11, 22, 33} 
Output :  -1



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 primeOccurences() that takes an array (arr), sizeOfArray (n), integer value K, and return the array of the elements that have prime frequency with their frequency >=K in sorted form. The driver code takes care of the printing.

Expected Time Complexity: O(N*SQRT(N)).
Expected Auxiliary Space: O(N).

 

Constraints:
1 ≤ N ≤ 105
1 ≤ K ≤ 100
1 ≤ A[i] ≤ 105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Numbers with prime frequencies greater than or equal to k

Output Window