Apple OA Interview Question: Maximum Sum of a Circular Subarray

18 Views
No Comments

Given an integer array, find the maximum sum of a contiguous subarray.

Update the solution when the array is circular, meaning the last element connects to the first element.

This problem asks for the maximum sum of a contiguous subarray in both a normal array and a circular array. A standard approach uses Kadane’s algorithm to compute the maximum subarray sum, then for the circular case compares it with total sum minus the minimum subarray sum, which represents a wraparound subarray. One important edge case is when all numbers are negative, where the non-circular maximum should be returned directly.

END
 0