You are viewing a single comment's thread. Return to all comments →
Python3: another O(N) (??? maybe ???)
def minimumBribes(q): seen = set() bribes = {n: set() for n in range(0, len(q) + 1)} for n in q: seen.add(n) m = n - 1 while m > 0 and m not in seen: bribes[n].add(m) m -= 1 bribes[n] |= (bribes[m] - seen) if len(bribes[n]) > 2: return print('Too chaotic') print(sum(len(v) for v in bribes.values()))
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
Python3: another O(N) (??? maybe ???)