Implement Kadane max-sum subarray, prove correctness

Given an integer array nums, return the largest sum of a contiguous subarray.

For every nonempty nums the selected subarray must contain at least one element. The empty selection is not a candidate, so an all-negative array returns its largest element, which is the least negative value. The maximum over a nonempty collection of nonempty subarrays is always attained, so this answer always exists.

For an empty nums there is no nonempty subarray at all, and the contract reports 0. The empty array is the only input for which the empty selection is reported; every nonempty input is answered by a nonempty subarray.

Examples
Input: []
Output: 0
Hints

Implement Kadane max-sum subarray, prove correctness

Given an integer array `nums`, return the largest sum of a contiguous subarray.