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.
1 parent fbadcf9 commit ff23947Copy full SHA for ff23947
z-revision/stock sPan.cpp
@@ -0,0 +1,40 @@
1
+#include<stack>
2
+int* stockSpan(int *arr, int size) {
3
+ // Write your code here
4
+ int * ans = new int [size];
5
+
6
+ stack < pair<int , int > > s ;
7
8
+ int index = 0 ;
9
10
+ for(int i = 0 ; i< size ; i++)
11
+ {
12
+ if(s.size()==0)
13
14
+ ans [ index++] = -1;
15
+ }
16
+ else if( s.top().first >= arr[i])
17
18
+ ans[index++] = s.top().second;
19
20
+ else
21
22
+ while( s.size() and s.top().first< arr[i])
23
+ s.pop();
24
25
26
+ ans [index++] = -1;
27
28
29
30
31
32
33
+ s.push({ arr[i] , i });
34
35
+ for(int i =0 ; i< size ; i++)
36
+ ans[i] = i- ans[i];
37
38
+ return ans ;
39
40
+}
0 commit comments