• + 7 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]);
    

    }

    This can be done in linear time.