Computer Science, asked by saurav4089, 11 months ago

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 helloitsme007420
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