You are viewing a single comment's thread. Return to all comments →
C++ solution :
string balancedSums(vector<int> arr) { vector<int> lsums(arr.size()), rsums(arr.size()); lsums[0]=0; rsums[arr.size()-1]=0; for (int i=1;i<arr.size();i++) lsums[i]=lsums[i-1]+arr[i-1]; for (int i=arr.size()-2;i>=0;i--) rsums[i]=rsums[i+1]+arr[i+1]; for (int i=0;i<arr.size();i++) if (lsums[i]==rsums[i]) return "YES"; return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Array
You are viewing a single comment's thread. Return to all comments →
C++ solution :