I was recently challenged with the following puzzle ...
Find the maximum subsequence sum of a list of integers.
Here's a list ...(1, 2, -4, 1, 3, -2, 3, -1).
The maximum subsequence sum is 5 = 1+3-2+3. One does not need to remember which subsequence yields the maximum, thus ties are not important
Allegedly, the trick is to note that one can discard subsequences as soon as the sum goes down when processing linearly.
How would one do this "functionally," without generating all subsequences first?
After some years of practice I now think more about sets, and operations on them, rather than serial - procedural - operations on sequences. As this community will understand, often the set-based approach proves to be faster and more transparent.
A non-procedural solution to this puzzle is eluding me.
Thank you.