Created
September 26, 2022 10:24
-
-
Save Vaib215/b13ba56e8de31de7c5dc44312a48dfc3 to your computer and use it in GitHub Desktop.
Kadane's Algorithm => TC -> O(N)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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