MCPcopy Index your code
hub / github.com/careercup/ctci / maxSubArray

Method maxSubArray

java/Chapter 18/Question18_12/QuestionC.java:37–53  ·  view source on GitHub ↗
(int array[], int N)

Source from the content-addressed store, hash-verified

35 }
36
37 public static int maxSubArray(int array[], int N) {
38 int maxSum = 0;
39 int runningSum = 0;
40
41 for (int i = 0; i < N; i++) {
42 runningSum += array[i];
43 maxSum = Math.max(maxSum, runningSum);
44
45 /* If running_sum is < 0 no point in trying to continue the
46 * series. Reset. */
47 if (runningSum < 0) {
48 runningSum = 0;
49 }
50 }
51
52 return maxSum;
53 }
54
55 public static void main(String[] args) {
56 int[][] matrix = AssortedMethods.randomMatrix(5, 7, -100, 100);

Callers 1

maxSubMatrixMethod · 0.95

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected