Maximum Subarray (Rust)
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.
max_subarray(&[-2, 1, -3, 4, -1, 2, 1, -5, 4]) // 6 (subarray [4, -1, 2, 1])
max_subarray(&[-3, -1, -2]) // -1
Grading
Your solution.rs is compiled together with a trusted tests.rs (which include!s it) using
rustc --test. Only solution.rs is yours to edit.
Sign in to submit your solution.