Oct-29-2021, 06:54 AM
(This post was last modified: Oct-29-2021, 07:43 AM by Gribouillis.)
A new version for python >= 3.8
It took me a while to reach this quintessence of a function. I hope it will become a must in interviews from now on!
from operator import add, sub from itertools import accumulate, tee def gribmax2(iterable): s, t = tee(accumulate(iterable, add, initial=0)) return max(map(sub, s, accumulate(t, min)))It seems to agree with Deanhystad's version on 100000 arrays of length 100 with values in the range(-1000, 1000).
It took me a while to reach this quintessence of a function. I hope it will become a must in interviews from now on!