You are viewing a single comment's thread. Return to all comments →
Another Python 3 solution...
def runningTime(arr): s = 0 l = { i:x for i,x in enumerate(arr)} for i in range(2,len(arr)+1): x = sorted(arr[:i]) _max = float("-inf") _min = float("inf") c = False for j,n in enumerate(x): if l[j] != n: _max = max(_max,j) _min = min(_min,j) l[j] = n c = True if c: s += _max - _min arr[:i] = x return s
Seems like cookies are disabled on this browser, please enable them to open this website
Running Time of Algorithms
You are viewing a single comment's thread. Return to all comments →
Another Python 3 solution...