Suppose you are given an integer array. How will you find the contiguous subarray with largest sum?
The elements in the array are either all positive or positive and negative or all negative. We can use Kadane's algorithm as :
The above algorithm will return zero when all the elements in the array is negative integers. The variable maximumSum represents the maximum sum. Time complexity = \( O(n) \). public static int[] findMaxSumSubarray(int[] array){ |