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.
Answers
Answered by
4
Answer:
int countSpecials(int arr[], int sizeof_array, int K){
int f = floor(sizeof_array/K), count = 0,c=1;
vector<bool> ar(sizeof_array,false);
// Your code here
for(int i=0;i<sizeof_array;i++){
if(ar[i]==true){
continue;
}
for(int j=i+1;j<sizeof_array;j++){
if(arr[i]==arr[j]){
c++;
ar[j]=true;
}
}
if(c==f){
count++;
}
c=1;
}
return count;
}
Explanation:
Similar questions
Science,
6 months ago
Math,
6 months ago
History,
11 months ago
Political Science,
11 months ago
Math,
1 year ago