Thanks for breaking this down. My head was hurting.
Thanks! Chart really makes this solution much more clear
This solution took me one entire day plus the night to figure it out. Very very clever!
While your point is interesting, it goes without saying. Changes to the task are outside the task's scope.
spoiler flag, plz... x/ (all comments are visible through the dashboard)
This comment is hidden because it contains spoiler information about the solution
The fact that lightest's question is 3 years old and no-one has answered it may indicate that no-one here actually had such a thought process, i.e. the task was recognised as "known problem x, with known solution y" and the solution was just copied from somewhere, and all the explanations of it are canned (which is why none of them make sense from the perspective of someone who's only familiar with the task description). So, if you're like lightest (or me), don't be too disheartened if you couldn't come up with this solution from scratch from the task description. There may be only one person in the history of the world who's done that, and they may have even started from a clearer task description!
That would be a different task.
It returns the correct solution, 7.
This great answer wasn't making intuitive sense to me so i used a chart library to help me grock what's going on... it helps me visualize what's going on. Check it out.
This fails on some use cases, e.g. [-2, 1, 2, -2, -2, 7]