Here is a code snippet of a function that takes vector of strings (vector of customer names) and need to find names which occurs with some frequency. How to make it run faster (faster than 2 seconds especially operating with larger sets of data). This function is the all functionality of a program.
Thanks in advance.
vector<string> most_active(vector<string> &customers) {
vector<string> result;
double p = (double)customers.size()*5/100;
for(string &customer: customers) {
if(find(result.begin(), result.end(), customer) != result.end())
continue;
if(count(customers.begin(), customers.end(), customer) >= p)
result.push_back(customer);
}
sort(result.begin(), result.end());
return result;
}
I tried to pass data by reference instead of passing by value, but it didn't help