


The first line of input contains a single integer ‘N’ denoting the number of elements in the array/list.
The second line of input contains ‘N’ single space-separated integers, denoting the elements of the array.
Print the maximum possible sum of any subarray of the array/list.
Note: You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= N <= 5*10^5
-10^9 <= ARR[i] <=10^9
Time Limit: 1sec
We will iterate through all possible boundaries of the subarrays in the given array with the help of two nested loops.
Then, we will iterate through each subarray with the help of another loop and find the sum of the subarray. We will maintain the maximum subarray sum through our iterations and finally return it.
We will iterate through all possible subarrays of the array with the help of two nested loops. We will maintain the maximum subarray sum/answer through our iterations and finally return it.
The algorithm will be-
The main observation here is that the optimal subarray will have no prefix with a negative sum. This is because we can remove the prefix with a negative sum from our optimal subarray which will only increase our subarray sum/answer.
The algorithm will be -