• + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/OqevjJbsN2Q

    void plusMinus(vector<int> arr) {
        double sp, sn, sz, pa = 1.0 / arr.size();
        sp = sn = sz = 0;
        for(int i = 0; i < arr.size(); i++){
            if(arr[i] > 0) sp+= pa;
            else if(arr[i]<0) sn+= pa;
            else sz+= pa;
        }
        cout << setprecision(6) << fixed;
        cout << sp <<endl;
        cout << sn <<endl;
        cout << sz <<endl;
    }