N integers, find the contiguous non-empty subarray that has the largest sum and output that sum.
N (1 ≤ N ≤ 200,000), the number of elements in the array.N space-separated integers A[0], A[1], ..., A[N-1] (-10^9 ≤ A[i] ≤ 10^9).Input:
9
-2 1 -3 4 -1 2 1 -5 4
Output:
6
Explanation:
The contiguous subarray [4, -1, 2, 1] has the largest sum: 4 + (-1) + 2 + 1 = 6.
Input:
5
5 4 -1 7 8
Output: ```text 23
**Explanation:**
The entire array `[5, 4, -1, 7, 8]` has the sum: `5 + 4 + (-1) + 7 + 8 = 23`.
Case 1
5 5 4 -1 7 8
23
Case 2
9 -2 1 -3 4 -1 2 1 -5 4
6
Input
5 5 4 -1 7 8
Expected Output
23
Run or submit your code to see output here.