A trader wants to find the most profitable contiguous period in a series of daily profit/loss values. Given an array of integers profits, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
- An array of integers
profits.
- An integer representing the maximum sum.
- 1 <= profits.length <= 10^5
- -10^4 <= profits[i] <= 10^4
Input: profits = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6
Explanation: [4, -1, 2, 1] has the largest sum = 6.