Count the Specials - Java
Submissions: 3867   Accuracy:

22.01%

  Difficulty: Easy   Marks: 2

Given an arry A (may contain duplicates) of N elements and a positive integer K. The task is to count the number of elements which occurs exactly floor(N/K) times in the array.
Hint: You may use hashing or brute-force.

Input:
First line of input contains number of testcases. For each testcase, there will be two lines, first of which contains N and K and second line contains array elements.

Output:
For each testcase, print the count of elements in the array which occurs exactly floor(N/K) times.

Constrains:
1 <= T <= 100
1 <= N <= 103
1 <= Ai <= 103

User Task:
Your task is to complete the function countSpecials() which should count the elements which occurs exactly floor(N/K) times.

Example:
Input:

1
5 2
1 4 1 2 4

Output:
2

Explanation:
Testcase 1:
In the given array, 1 and 4 occurs floor(5/2) = 2 times. So count is 2.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Dhiman Mayank


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.