CT003

Rune River Gold Rush

MediumAcceptance: 0.0%

The Rune River flows through the valley, carrying gold nuggets along its path. Each nugget has a value (positive or negative ÔÇö some are fool's gold that cost energy to collect). A miner can choose any contiguous segment of the river to pan for gold. Given an array of numbers representing gold values along the river, find the maximum sum of any contiguous subarray. The miner can also choose to pan nothing, in which case the sum is 0. Solve this in O(n) time.

Example 1:

Input: 6 34 -50 42 14 -5 86
Output: 137

Example 2:

Input: 4 -5 -1 -8 -9
Output: 0

Constraints:

1 <= n <= 10^5 -10^4 <= arr[i] <= 10^4

Tags:

arrays dynamic-programming
Loading...
Test Cases:No test cases
No test cases available.
Coding Problem Not Found | CodeTikki