Skip to content

Commit

Permalink
Added STPAR
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet29 committed Jun 9, 2020
1 parent 2db2942 commit 11617ab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions spoj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Name | Status | Tags | Languages
[PRIME1](PRIME1.py) | :rocket: | `#number-theory` | Python
[SAMER08F](SAMER08F.cpp) | :heavy_check_mark: | *no tags* | [Python](SAMER08F.py), [C++](SAMER08F.cpp)
[SEQ](SEQ.cpp) | :heavy_check_mark: | `#transformation-matrix` `#recursive` `#series` | C++
[STPAR](STPAR.py) | :heavy_check_mark: | `#stack` `#ad-hoc-1` | Python
[TEST](TEST.py) | :heavy_check_mark: | `#basic` `#tutorial` `#ad-hoc-1` | Python
[TOANDFRO](TOANDFRO.py) | :heavy_check_mark: | `#ad-hoc-1` | Python

Expand Down
42 changes: 42 additions & 0 deletions spoj/STPAR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
n = int(input())

while(n != 0):
arr = [int(i) for i in input().split()]
newarr = []
stack = []
ans = 'yes'
i = 0

while(i < n and len(newarr) == 0):
if arr[i] == 1:
newarr.append(1)
else:
stack.append(arr[i])
i += 1

while(i < n):
while(len(stack) > 0):
if stack[-1] - 1 == newarr[-1]:
newarr.append(stack.pop())
else:
break
if arr[i] - 1 == newarr[-1]:
newarr.append(arr[i])
else:
stack.append(arr[i])
i += 1

while(len(stack) > 0):
if len(newarr) > 0:
if stack[-1] - 1 == newarr[-1]:
newarr.append(stack.pop())
else:
ans = 'no'
break
else:
ans = 'no'
break

print(ans)

n = int(input())

0 comments on commit 11617ab

Please sign in to comment.