Skip to content

Commit

Permalink
Merge pull request #101 from Aaryan8751/Aaryan
Browse files Browse the repository at this point in the history
Added Stock_Span.py
  • Loading branch information
ultimatecoder2 authored Oct 2, 2021
2 parents 3c780fc + 0799d8e commit c2dc6f6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Good-First-Issues/stock_span.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

from sys import stdin

def calculateSpan(price, n) :

li=[1]
s=[0]
for i in range(1,len(price)):
c=1
while len(s)!=0 and (price[i]>price[s[-1]]):
c+=1
s.pop()

if len(s)==0:
li.append(i+1)
else:
li.append(i-s[-1])
s.append(i)
return li

def printList(arr) :
for i in range(len(arr)) :
print(arr[i], end = " ")

print()


def takeInput():
size = int(stdin.readline().strip())

if size == 0 :
return list(), 0

price = list(map(int, stdin.readline().strip().split(" ")))

return price, size

price, n = takeInput()

output = calculateSpan(price, n)
printList(output)

0 comments on commit c2dc6f6

Please sign in to comment.