Complete the code to initialize the variable that stores the maximum sum found so far.
int maxSoFar = [1];We initialize maxSoFar to the smallest possible integer to ensure any subarray sum will be larger.
Complete the code to update the current subarray sum by adding the current element.
currentSum = currentSum [1] nums[i];We add the current element to the current sum to extend the subarray.
Fix the error in the code to reset currentSum when it becomes negative.
if (currentSum [1] 0) currentSum = 0;
If the current sum is less than zero, we reset it to zero to start a new subarray.
Fill both blanks to update maxSoFar if currentSum is greater.
if (currentSum [1] maxSoFar) maxSoFar = [2];
If currentSum is greater than maxSoFar, update maxSoFar to currentSum.
Fill all three blanks to complete the Kadane's algorithm loop.
for (int [1] = 0; i < [2]; i++) { currentSum = currentSum + nums[i]; if (currentSum > maxSoFar) maxSoFar = [3]; if (currentSum < 0) currentSum = 0; }
The loop variable is i, iterating from 0 to nums.Length. We update maxSoFar with currentSum when currentSum is greater.
