Please convert the code toC 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, //then the location will have value 2 //instead of the keys itself map 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=""> cin >> n; vector arr(n, 0); cout < "input="" the="" array=""> 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)=""><> return 0;}
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, //then the location will have value 2 //instead of the keys itself map 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=""> cin >> n; vector arr(n, 0); cout < "input="" the="" array=""> 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)=""><> return 0;}
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=""> cin >> n;
vector arr(n, 0); cout < "input="" the="" array=""> 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)=""><> return 0;}
cout < "input="" the="" array="">
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)=""><> return 0;}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here