MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / Kadane

Class Kadane

Programs/kadane.java:5–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import java.util.*;
4
5class Kadane
6{
7 public static void main (String[] args)
8 {
9 int [] a = {10,13,11,22,34,50,20,80};
10 System.out.println("Sub array with maximum sum is " +maxSubArray(a));
11
12 }
13
14 static int maxSubArray(int a[])
15 {
16 int l = a.length;
17 int max = Integer.MIN_VALUE, max_ending = 0;
18 for (int i = 0; i < l; i++)
19 {
20 max_ending = max_ending + a[i];
21 if (max < max_ending)
22 max = max_ending;
23 if (max_ending < 0)
24 max_ending = 0;
25 }
26 return max;
27 }
28}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected