forked from larissalages/code_problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfish.py
More file actions
39 lines (36 loc) · 858 Bytes
/
fish.py
File metadata and controls
39 lines (36 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from collections import deque
def solution(A, B):
n = 0
stk1 = deque()
stk2 = deque()
# insert values in stack
for i in range(len(A)-1, -1, -1):
stk1.append(i)
if len(stk1) > 0:
p = stk1.pop()
else:
return 0
if len(stk1) > 0:
q = stk1.pop()
else:
return 1
while True:
if not (B[p] == 1 and B[q]==0):
stk2.append(p)
p = q
if len(stk1) > 0:
q = stk1.pop()
else:
break
else:
if A[q] > A[p]:
if len(stk2) > 0:
p = stk2.pop()
else:
break
else:
if len(stk1) > 0:
q = stk1.pop()
else:
break
return len(stk2) + 1