please convert the code to C language // C++ program to find minimum deletion // to make all elements same #include using namespace std; int minimum_no_of_deletion(vector arr, int n) { //create a hash table where for each key //the hash function is h(x)=x //we will use stl map as hash table and //will keep frequencies stored //so say two keys are mapping to the same location,
please convert the code to C language
// C++ program to find minimum deletion
// to make all elements same
#include <bits/stdc++.h>
using namespace std;
int minimum_no_of_deletion(
{
//create a hash table where for each key
//the hash function is h(x)=x
//we will use stl map as hash table and
//will keep frequencies stored
//so say two keys are mapping to the same location,
//then the location will have value 2
//instead of the keys itself
map<int, int> hash;
for (auto i : arr) { //for each number
hash[i]++;
}
//now to make all elements same
//we need to keep only the keys with
//maximum frequency
//we need to delete the other keys
//so find the key with max frequency
int maxfreq = 0;
for (auto it = hash.begin(); it != hash.end(); it++) {
if (it->second > maxfreq) {
maxfreq = it->second;
}
}
//so we need to dlete rest of
//the elements n-maxfreq
return n - maxfreq;
}
int main()
{
int n;
cout << "Enter number of elements\n";
cin >> n;
vector<int> arr(n, 0);
cout << "Input the array elements\n";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
cout << "Minimum number of deletion required to make all elements same is: ";
cout << minimum_no_of_deletion(arr, n) << endl;
return 0;
}
Output:
Step by step
Solved in 2 steps