The below code is for the problem “equal elements”. I am not able to understand what is the use of variable ‘f’ in the given code for the problem. Please help! .When I am running the with ‘f’ , the output is correct, but when submitting the code code without ‘f’ it is showing wrong answer.
NOTE: The below code is correct.
include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::vector<int> arr;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
arr.push_back(a);
}
sort(arr.begin(),arr.end());
int c = 0;
int f = 0;
int def = arr[0];
for (int i = 0; i < n-1; i++) {
if (arr[i] != arr[i+1]){
c = 0;
}
else {
c++;
}
if (c > f){
f = c;
def = arr[i];
}
}
int count = 0;
for (int i = 0; i < n; i++) {
if (arr[i] != def) count++;
}
std::cout << count << std::endl;
}
return 0;
}