CJCoding With Joseph
15free / daySign inCreate account

Maximum Subarray Sum

The array {-2, 1, -3, 4, -1, 2, 1, -5, 4} is given. Find the largest possible sum of any CONTIGUOUS subarray (a run of one or more adjacent elements) and print it (see Expected Output).

The best run is 4, -1, 2, 1, which sums to 6. Use Kadane's algorithm: track the best sum ending at the current position.

Expected Output:

6

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.