I have tested all the test cases that i found and my code works properly for it …but when i submit i get a WA
please help me with this…here is my code
#include
#include
using namespace std;
class chef{
public:
void accept_process_display();
};
void chef::accept_process_display(){
bool condition,found;
int n,required;
int temp;
cin>>n;
vector queue(n);
vector stack;
for(int i=0;i<n;i++){
cin>>queue[i];
}
cin>>temp;
condition=true;
required=0;
while(condition && required<n){
required+=1;
found=false;
if(!queue.empty()){
if(queue.front()==required){
queue.erase(queue.begin());
found=true;
}
}
if(!found){
if(!stack.empty()){
if(stack.back()==required){
stack.pop_back();
found=true;
}
}
if(!found){
while(!queue.empty() && !found){
if(queue.front()==required){
found=true;
queue.erase(queue.begin());
}
else{
stack.push_back(queue.front());
queue.erase(queue.begin());
}
}
if(!found){
condition=false;
}
}
}
}
if(required==n && condition){cout<<"yes\n";}
else{cout<<"no\n";}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
chef obj;
obj.accept_process_display();
return 0;
}