Implement Kadane max-sum subarray, prove correctness
Analyze the implement kadane max-sum subarray, prove correctness.
Examples
Input: "test_input_1"
Output: "output_1"
Input: "test_input_2"
Output: "output_2"
Hints
Consider how Kadane's algorithm maintains a running sum and decides when to reset it, leveraging the optimal substructure property of the problem.
Prove correctness by induction: show that the algorithm's invariant (max sum ending at index i) holds for all i, and that the global maximum is correctly tracked.
Analyze edge cases (all negative numbers, single-element array) and explain why Kadane's algorithm handles them without additional modifications, using the recurrence relation `dp[i] = max(nums[i], dp[i-1] + nums[i])`.
Implement Kadane max-sum subarray, prove correctness
Analyze the implement kadane max-sum subarray, prove correctness.