Skip to content

Latest commit

 

History

History
19 lines (14 loc) · 636 Bytes

File metadata and controls

19 lines (14 loc) · 636 Bytes

Problem 2: Maximum Wealth Subsegment

Problem Statement

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.

Input Format

  • An array of integers profits.

Output Format

  • An integer representing the maximum sum.

Constraints

  • 1 <= profits.length <= 10^5
  • -10^4 <= profits[i] <= 10^4

Example

Input: profits = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6
Explanation: [4, -1, 2, 1] has the largest sum = 6.