Mental Model
Find the biggest sum of a continuous part of the list by keeping track of the best sum ending at each position.
Analogy: Imagine walking along a path with ups and downs in height. You want to find the highest hill you can climb without stopping midway. You keep track of your current climb and reset if you start going downhill too much.
Array: [ -2, 1, -3, 4, -1, 2, 1, -5, 4 ] Index: 0 1 2 3 4 5 6 7 8 At each step, we track current_sum and max_sum: current_sum ↑ max_sum ↑
