Question:codility Lesson7 Fish
My Answer:
def solution(A,B):
cnt = 0
downstream = []
downcnt = 0
for i in range(len(A)):
if B[i] == 1:
downstream.append(A[i])
else:
while downcnt != 0:
if downstream[-1] < A[i]:
downcnt -= 1
downstream.pop()
else:
break
else:
cnt += 1
cnt += len(downstream)
return cnt