Complete the code to initialize the maximum sum with the first element of the array.
maxSoFar := nums[[1]]We start with the first element at index 0 as the initial maximum sum.
Complete the code to update the current sum by choosing the maximum between the current number and the sum plus current number.
currentSum = max(nums[i], currentSum [1] nums[i])
We add the current number to the current sum or start fresh from the current number, whichever is larger.
Fix the error in the max function to correctly return the larger of two integers.
func max(a, b int) int { if a [1] b { return a } return b }
The function should return 'a' if 'a' is greater than 'b'.
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 function.
func maxSubArray(nums []int) int {
maxSoFar := nums[[1]]
currentSum := nums[0]
for i := 1; i < [2]; i++ {
currentSum = max(nums[i], currentSum [3] nums[i])
if currentSum > maxSoFar {
maxSoFar = currentSum
}
}
return maxSoFar
}Start maxSoFar at index 0, loop until length of nums, and add currentSum plus nums[i].
