MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / maxSubarraySum

Method maxSubarraySum

Kadane's_Algorithm.java:6–19  ·  view source on GitHub ↗
(int arr[], int n)

Source from the content-addressed store, hash-verified

4 // n: size of array
5 //Function to find the sum of contiguous subarray with maximum sum.
6 long maxSubarraySum(int arr[], int n){
7
8 // Your code here
9 long maxSoFar=arr[0];
10 long curSum=arr[0];
11
12 for(int i=1;i<arr.length;i++)
13 {
14 curSum = Math.max(arr[i], curSum+arr[i]);
15 maxSoFar = Math.max(maxSoFar, curSum);
16 }
17
18 return maxSoFar;
19 }
20}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected