Sherlock and Array

  • + 0 comments

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

    string balancedSums(vector<int> arr) {
        int ls = 0, rs = accumulate(arr.begin(), arr.end(), 0);
        for(int i = 0; i < arr.size(); i++){
            rs -= arr[i];
            if(i != 0) ls += arr[i-1];
            if(ls == rs) return "YES";
        }
        return "NO";
    }