Back to problems

Maximum Sum Subarray with Equal Endpoints

Algorithm · Google · Medium

Problem: Maximum Subarray Sum with Equal Endpoints For an integer array a, choose two positions (i, j) that meet both conditions: 0 <= i <= j < n a[i] == a[j] From every valid choice, consider the inclusive segment total: S(i,j) = a[i] + a[i+1] +... + a[j] Output the indices i j for a pair whose segment total is as large as possible. When more than one valid pair has the greatest total, returning any one of them is acceptable. Constraints 1 <= n <= 2e5 -1e9 <= a[i] <= 1e9…

Checking your access…