Easy
JAVA-001javaMax Subarray Sum (Stock Analytics)
Problem
Given daily profit/loss numbers for a stock, find the maximum total profit over any contiguous window of days (Kadane's algorithm — a trading interview classic).
Input
Line 1: n. Line 2: n space-separated integers.
Output
A single integer — max contiguous sum.
Constraints
1 ≤ n ≤ 10^5, -10^4 ≤ a[i] ≤ 10^4
Sample input
9 -2 1 -3 4 -1 2 1 -5 4
Sample output
6
Explanation
The subarray [4, -1, 2, 1] has the maximum sum = 6.
dparrayskadane@Amazon@Microsoft@Goldman Sachs
Visible test cases
in: 9 -2 1 -3 4 -1 2 1 -5 4
out: 6
in: 1 5
out: 5
Your solution — run it, use AI if stuck
java
