From 085fa299ff8bc0b87300922a94e7a7d9e03070e5 Mon Sep 17 00:00:00 2001 From: Rodolfo P A <6721075+rodoufu@users.noreply.github.com> Date: Mon, 6 Jul 2026 14:52:06 -0300 Subject: [PATCH] Create fish.py --- codility_new/fish.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 codility_new/fish.py diff --git a/codility_new/fish.py b/codility_new/fish.py new file mode 100644 index 0000000..952cfe6 --- /dev/null +++ b/codility_new/fish.py @@ -0,0 +1,21 @@ +# https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/ +def solution(A, B): + count = 0 + + fix_downstream = [] + + for i in range(len(A)): + going_up = B[i] == 0 + + if not going_up: + fix_downstream.append(A[i]) + else: + while fix_downstream: + if A[i] > fix_downstream[-1]: + fix_downstream.pop() + else: + break + if len(fix_downstream) == 0: + count += 1 + + return count + len(fix_downstream)