Skip to content

Instantly share code, notes, and snippets.

@tuanchauict
Created March 9, 2018 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuanchauict/d16f75acd372bd02bf629aed07f606ba to your computer and use it in GitHub Desktop.
Save tuanchauict/d16f75acd372bd02bf629aed07f606ba to your computer and use it in GitHub Desktop.
def solution(A, B):
go_up_count = 0
s1 = []
for i in range(0, len(A)):
a = A[i]
b = B[i]
if b == 0:
if not s1:
go_up_count += 1
else:
while s1 and a > s1[-1]:
s1.pop()
if not s1:
go_up_count += 1
else:
s1.append(a)
return go_up_count + len(s1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment