Skip to content

Commit 3f64779

Browse files
authored
Stock_Span Problem
Initial File
1 parent c8b9333 commit 3f64779

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Stock_Span Problem

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def calculateSpan(price, S):
2+
n = len(price)
3+
st = []
4+
st.append(0)
5+
S[0] = 1
6+
7+
for i in range(1, n):
8+
while (len(st) > 0 and price[st[-1]] <= price[i]):
9+
st.pop()
10+
if len(st) <= 0:
11+
S[i] = i + 1
12+
else:
13+
S[i] = (i - st[-1])
14+
st.append(i)
15+
return S
16+
17+
18+
price = [60,70,80,100,90,75,80,120]
19+
S = [0 for i in range(len(price))]
20+
print(calculateSpan(price, S))

0 commit comments

Comments
 (0)