Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector <int> calculateSpan(int price[], int n)
- {
- // Your code here
- vector<int> res;
- stack<int> st;
- res.push_back(1);
- st.push(0);
- for(int i=1; i<n; i++)
- {
- while(st.empty()==false && price[st.top()] <= price[i] )
- {
- st.pop();
- }
- if(st.empty()){
- res.push_back(i+1);
- }
- else
- {
- res.push_back(i-st.top());
- }
- st.push(i);
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement