Skip to content

Commit

Permalink
Add compilers and parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
thorvn committed Sep 25, 2022
1 parent cf5fcd7 commit 1a36f7b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Lecture-04-stack-and-queue/compilers-and-parsers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
n = int(input())

for j in range(n):
t = input()

stack = []
count = 0
max_count = 0

for i in range(len(t)):
if t[i] == '<':
stack.append(t[i])
else:
if len(stack) > 0:
stack.pop()
count += 1
else:
break
# update max_count after pop from stack
if len(stack) == 0:
max_count = count

print(max_count * 2)

0 comments on commit 1a36f7b

Please sign in to comment.