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.
private static int solve(int[] arr, int start, int end, long totalSum) {
// cant divide more when sum is odd
// return when start and end point are same
if ((totalSum % 2 != 0) || (start == end)) {
return 0;
}
long reqSum = totalSum / 2;
long tempSum = 0;
for (int i = start; i <= end; i++) {
tempSum += arr[i];
if (tempSum == reqSum) {
// solution++;
if (i - start > end - i - 1) {
return 1 + solve(arr, start, i, reqSum);
} else if (i - start < end - i - 1) {
return 1 + solve(arr, i + 1, end, reqSum);
} else if (i - start == end - i - 1) {
return 1 + (Math.max(solve(arr, start, i, reqSum),
solve(arr, i + 1, end, reqSum)));
}
// break;
}
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nikita and the Game
You are viewing a single comment's thread. Return to all comments →
Please help me with my code, cant understand where it went wrong - https://www.hackerrank.com/contests/hourrank-7/challenges/array-splitting/submissions/code/5838224
private static int solve(int[] arr, int start, int end, long totalSum) {