Answers for "use of kadane algorithm is: maximum product subarray in an array maximum product subsequence in an array maximum sum subarray in an array maximum sum subsequence in an array"

C#
3

maximum sum subarray

public static int SumArray()
{
    var arr = new int[]{ -2, -4, -5, -6, -7, -89, -56 };
    var sum = 0;
    var max = arr[0];
    foreach (var item in arr)
    {
        sum += item;
      // sum = Math.Max(sum,0); resting here will not give  expected output
        max = Math.Max(sum,max);
        sum = Math.Max(sum,0);
    }
    return max;
}
Posted by: Guest on March-01-2022

Code answers related to "use of kadane algorithm is: maximum product subarray in an array maximum product subsequence in an array maximum sum subarray in an array maximum sum subsequence in an array"

C# Answers by Framework

Browse Popular Code Answers by Language