Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove error in open sock problem code #1

Closed
utkarsh357 opened this issue Oct 3, 2022 · 3 comments
Closed

remove error in open sock problem code #1

utkarsh357 opened this issue Oct 3, 2022 · 3 comments
Assignees

Comments

@utkarsh357
Copy link
Owner

No description provided.

@utkarsh357 utkarsh357 changed the title Add open sock problem code remove error in open sock problem code Oct 4, 2022
@utkarsh147-del
Copy link
Contributor

assign this to me

@utkarsh357
Copy link
Owner Author

do it

@utkarsh147-del
Copy link
Contributor

#include <bits/stdc++.h>
vector findSpans(vector &price) {
// Write your code here.

stack<int>s;
vector<int>arr;
s.push(-1);
for(int i=0;i<price.size();i++)
{
   // cout<<"top "<<s.top()<<endl;
//    cout<<"i "<<i<<endl;
    if(s.top()==-1)
        arr.push_back(1);
    else if(price[s.top()]>price[i])
    {
      //  cout<<"b"<<endl;
        arr.push_back(i-s.top());
    }
    else if(price[s.top()]<=price[i])
    {
    //    cout<<"c"<<endl;
        while(s.top()!=-1&&price[s.top()]<=price[i])
        {
            s.pop();
        }
     //    cout<<"top "<<s.top()<<endl;
        if(s.top()==-1)
        {
           // cout<<"i "<<i<<endl;
            arr.push_back(i+1);
        }
        else
            arr.push_back(i-s.top());
            
    }
    
  //  cout<<"ar "<<arr[arr.size()-1]<<endl;
    s.push(i);
}

return arr;

}

utkarsh147-del added a commit to utkarsh147-del/correction that referenced this issue Oct 4, 2022
utkarsh357 added a commit that referenced this issue Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants