import java.util.Arrays;
public class Program {
public static int maxSubArray(int[] arr) {
int maxSum = Integer.MIN_VALUE;
int currentSum = 0;
int size = arr.length;
for (int i = 0; i < size; i++) {
currentSum = Math.max(arr[i], currentSum + arr[i]);
maxSum = Math.max(currentSum, maxSum);
}
return maxSum;
}
public static void main(String[] args) {
int[] arr = {1, -2, 2, -3, 4, -1, -1, 2, 3, -5, 4}; // 4 + -1 + -1 + 2 + 3 = 7
System.out.println(maxSubArray(arr));
}
}
/*
run:
7
*/