I am not able to understand the question

i am not able to understand the question

@mohdkaifalam041,

You have to find the largest sum possible of elements in a contiguous subarray.

A simple solution is to iterate through all the elements of the array. For every element, calculate the max contiguous subarray sum starting from that element itself.

Time complexity: O(n2).
An efficient way is to use Kadane’s Algorithm . Kadane’s algorithm is a Dynamic Programming approach to find the largest sum of contiguous subarray with runtime of O(n).Simple idea of the Kadane’s algorithm is to look for all positive contiguous segments of the array . And keep track of maximum sum contiguous segment among all positive segments .

Algo:

1.Take two variables one for storing local max sum(max-ending-here) and global max sum(max-so-far).
2.Iterate over each each element of the array say a.

  2.1 max_ending_here = max_ending_here + a[i]
  2.2 if(max_ending_here < 0)   
        max_ending_here = 0
  2.3 if(max_so_far < max_ending_here)
        max_so_far = max_ending_here

3.max-so-far is the required max sum of contiguous subarray.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.