Greatest subsequential sum
Another solution, not translated from any other language:
For each starting position, we calculate all the subsets starting at that position. They are combined with the best subset ($max-subset) from previous loops, to form (@subsets). The best of those @subsets is saved at the new $max-subset.
Consuming the array (.shift) allows us to skip tracking the starting point; it is always 0.
The empty sequence is used to initialize $max-subset, which fulfils the "all negative" requirement of the problem.
Output:
Last updated