Skip to content

Commit c2dc6f6

Browse files
Merge pull request #101 from Aaryan8751/Aaryan
Added Stock_Span.py
2 parents 3c780fc + 0799d8e commit c2dc6f6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Good-First-Issues/stock_span.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
from sys import stdin
3+
4+
def calculateSpan(price, n) :
5+
6+
li=[1]
7+
s=[0]
8+
for i in range(1,len(price)):
9+
c=1
10+
while len(s)!=0 and (price[i]>price[s[-1]]):
11+
c+=1
12+
s.pop()
13+
14+
if len(s)==0:
15+
li.append(i+1)
16+
else:
17+
li.append(i-s[-1])
18+
s.append(i)
19+
return li
20+
21+
def printList(arr) :
22+
for i in range(len(arr)) :
23+
print(arr[i], end = " ")
24+
25+
print()
26+
27+
28+
def takeInput():
29+
size = int(stdin.readline().strip())
30+
31+
if size == 0 :
32+
return list(), 0
33+
34+
price = list(map(int, stdin.readline().strip().split(" ")))
35+
36+
return price, size
37+
38+
price, n = takeInput()
39+
40+
output = calculateSpan(price, n)
41+
printList(output)

0 commit comments

Comments
 (0)