This is one of the most classic algorithm problems and a gateway to understanding Kadane's algorithm, which is a fundamental greedy/DP technique.
Enable JavaScript for the full StreamPrep guide.