Back to problems

Maximum Length Balanced Subarray (Equal Sum Halves)

Algorithm · Ebay · Medium

Problem Statement You are given an integer array A of size n. A contiguous subarray A[l..r] (with 0 <= l <= r < n) is defined as a balanced-sum subarray when it satisfies two conditions: The subarray length len = r - l + 1 is even. Let mid = l + len/2 - 1 be the last index of the left half. The sum of the left half must equal the sum of the right half: sum(A[l..mid]) == sum(A[mid+1..r]) Your task is to return the maximum possible length of any balanced-sum subarray. If no…

Checking your access…