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.
// java method which passes 6 test cases, 7th test case fails. what is //the problem?
// Complete the balancedSums function below.
static String balancedSums(List<Integer> arr) {
int n = arr.size();
int i = 0;
int j = n-1;
int left = 0;
int right = 0;
while ( i < n && j >= 0)
{
if ( left == right && i == j) {
return "YES";
}
if ( left > right) {
right += arr.get(j);
j--;
} else
{
left += arr.get(i);
i++;
}
}
return "NO";
}
Sherlock and Array
You are viewing a single comment's thread. Return to all comments →
// java method which passes 6 test cases, 7th test case fails. what is //the problem? // Complete the balancedSums function below.