Intermediate Level
Implement the method maxSubarraySum that returns the largest sum of any contiguous subarray.
A subarray is a continuous block of the original array. The answer must use at least one element.
The task is designed to test careful handling of edge cases, not only the most common input.
- Use only the first
sizeelements. - Do not reorder elements.
- All-negative arrays should return the largest negative value.
At each position, decide whether to extend the previous subarray or start a new one. Track the best sum seen.