Skip to content

Instantly share code, notes, and snippets.

@Vaib215
Created September 26, 2022 10:24
Show Gist options
  • Save Vaib215/b13ba56e8de31de7c5dc44312a48dfc3 to your computer and use it in GitHub Desktop.
Save Vaib215/b13ba56e8de31de7c5dc44312a48dfc3 to your computer and use it in GitHub Desktop.
Kadane's Algorithm => TC -> O(N)
public static void maxSumKadane(int arr[]){
int currSum = 0, maxSum = Integer.MIN_VALUE;
for(int i=0; i< arr.length; i++) {
currSum += arr[i];
if(currSum < 0) currSum = 0;
maxSum = maxSum>currSum? maxSum:currSum;
}
System.out.println(maxSum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment