Maximum Subarray (Go)
Source: LeetCode #53
Topics: dynamic programming, array
Problem
Return the largest sum of any contiguous, non-empty subarray of nums (which is non-empty). Aim
for O(n) — this is Kadane's algorithm.
maxSubarray([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4}) // 6 (subarray [4, -1, 2, 1])
maxSubarray([]int{-3, -1, -2}) // -1
Only solution.go is yours to edit; it's compiled against the trusted solution_test.go.
Run
go test -v ./challenges/max-subarray/go/
Sign in to submit your solution.