MCPcopy Create free account
hub / github.com/apna-college/Alpha / maxSubarraySum3

Method maxSubarraySum3

1_Arrays/MaxSubarraySum.java:43–56  ·  view source on GitHub ↗
(int arr[])

Source from the content-addressed store, hash-verified

41
42 //Kadane's Algorithm
43 public static void maxSubarraySum3(int arr[]) {
44 int cs = 0;
45 int ms = 0;
46
47 for(int i=0; i<arr.length; i++) {
48 cs = cs + arr[i];
49 if(cs < 0) {
50 cs = 0;
51 }
52 ms = Math.max(ms, cs);
53 }
54
55 System.out.println("max subarray sum is : " + ms);
56 }
57 public static void main(String args[]) {
58 int arr[] = {1, -2, 6, -1, 3};
59 maxSubarraySum1(arr);

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected