We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3c780fc + 0799d8e commit c2dc6f6Copy full SHA for c2dc6f6
Good-First-Issues/stock_span.py
@@ -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