You are viewing a single comment's thread. Return to all comments →
// Complete the pickingNumbers function below.
int pickingNumbers(vector a) { int n = a.size(); vector<int> sol(100,0); //sort(a.begin(), a.end()); for(int i=0; i<n; i++){ sol[a[i]]++; } int pos = max_element(sol.begin(),sol.end()) - sol.begin(); //cout<<sol[pos]; return maxi(sol[pos+1]+sol[pos],sol[pos-1]+sol[pos]); }
int pickingNumbers(vector a) {
int n = a.size(); vector<int> sol(100,0); //sort(a.begin(), a.end()); for(int i=0; i<n; i++){ sol[a[i]]++; } int pos = max_element(sol.begin(),sol.end()) - sol.begin(); //cout<<sol[pos]; return maxi(sol[pos+1]+sol[pos],sol[pos-1]+sol[pos]);
}
This can be done in linear time.
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
// Complete the pickingNumbers function below.
This can be done in linear time.