You are viewing a single comment's thread. Return to all comments →
O(n) proposal basically each element is visited ~twice
def solve(arr): arr += [math.inf] A = [math.inf] s = 0 i = 0 while i < len(arr): if (e:= arr[i]) <= A[-1]: A.append(e) i += 1 continue n = 0 v = A[-1] while A[-1] == v: A.pop() n+=1 s += math.perm(n, 2) return s
Seems like cookies are disabled on this browser, please enable them to open this website
Jim and the Skyscrapers
You are viewing a single comment's thread. Return to all comments →
O(n) proposal
basically each element is visited ~twice