Maximum Subarray (C)
Topics: Kadane's algorithm, dynamic programming
Problem
int max_subarray(const int *nums, size_t n); // n >= 1
Return the largest sum of any contiguous subarray. Kadane: keep a running sum; drop it once it
goes negative (a fresh start beats carrying a deficit); track the best seen. O(n).
Run: cc -std=c11 -O2 -Wall tests.c -o /tmp/m && /tmp/m
Sign in to submit your solution.