#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; stackS; vectorv; vectorv1; int t; int s=1; for(int i=0;i<n+1;i++){ cin>>t; if(t!=0) v1.push_back(t); else break;} for(int i=0;i<v1.size();i++){ if(v1[i]!=s) S.push(v1[i]); else{ v.push_back(v1[i]); s++;}} while(!S.empty()){ v.push_back(S.top()); S.pop(); } int flag=0; for(int j=0;j<v.size()-1;j++){ if(v[j]>v[j+1]){ flag=1; cout<<“no”; break; } } if(flag==0) cout<<“yes”;
}
You do realise there are multiple test cases?
I gave it
4 4 3 2 1 4 1 4 2 3 4 1 4 3 2 0
and only got one answer instead of three.
Yes I do realize that,It would be helpful if you can see if there is any fault in algo
Which would be easier if the code gave an answer for every test case I gave it, and not just the first one.