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

Method maxSubarraySum1

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

Source from the content-addressed store, hash-verified

4public class MaxSubarraySum {
5 //bruteforce
6 public static void maxSubarraySum1(int arr[]) {
7 int largestSum = Integer.MIN_VALUE;
8
9 for(int i=0; i<arr.length; i++) {
10 for(int j=i+1; j<arr.length; j++) {
11 int currSum = 0;
12 for(int k=i; k<=j; k++) {
13 currSum += arr[k];
14 }
15 largestSum = Math.max(largestSum, currSum);
16 }
17 }
18
19 System.out.println("max subarray sum is : " + largestSum);
20 }
21
22 //optimization1 : Prefix Sum array
23 public static void maxSubarraySum2(int arr[]) {

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected