Maximum Subarray
Given an integer array nums, return the largest sum of any contiguous subarray (which must contain at least one element). This is the classic setup for Kadane's algorithm: at each element, either extend the current run or start fresh from here — whichever is larger.
maxSubArray([-2, 1, -3, 4, -1, 2, 1, -5, 4]); // 6 ([4, -1, 2, 1])
maxSubArray([-3, -1, -2]); // -1 (all negative — pick the largest)