Kadane's algorithm consists of a scan through the array values, computing at each position the maximum (positive sum) subarray ending at that position. This subarray is either empty (in which case its sum is zero) or consists of one more element than the maximum subarray ending at the previous position.
Usage of Kadane's algorithm
It is used to obtain the maximum subarray sum from an array of integers.
Code in Java: