We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I have used an implementation which takes care of that test case by itself. Here is a Java implementation which passes all test case in o(n) time.
privatestaticStringbalancedSums(List<Integer>arr){intsum=0;// get sum of all array index.for(inti=0;i<arr.size();i++){sum+=arr.get(i);}// initially left sum is zero.intleftSum=0;for(inti=0;i<arr.size();i++){//if left sum equals right sum print yes.if(leftSum==(sum-leftSum-arr.get(i))){return"YES";}leftSum+=arr.get(i);}return"NO";}
Sherlock and Array
You are viewing a single comment's thread. Return to all comments →
I have used an implementation which takes care of that test case by itself. Here is a Java implementation which passes all test case in o(n) time.