I am getting tle for this question I dont kw why please help me know about this
question link: http://www.spoj.com/problems/STPAR/
my code link:http://ideone.com/6PKugy
You can check you code manually:
First, j=0; then in “while (j < n)”, check some conditions:

j!=n1, so
if(j==n1){
while(s.empty()==true){
if (s.top()==z){
s.pop();
}
else{
flag=1;
break;
}
}
}
will not be run.

j=0, so a[j]=4 != z, which is equal 1, so
if(a[j]==z){
cout<<“1”;
z++;
if(j<n1){
j++;
}
}
will not be run, check else condition:
else if(!s.empty()){
cout<<"2";
if(s.top()>z){
s.push(a[j]);
j++;
}
else if(s.top()==z+1){
s.pop();
}
}
from begin of code, you haven’t push anything into stack, so stack will be empty, and as it is empty, it will never have anything called “top” as you write here: “s.top()==z+1”, so after many conditions, variable j won’t be changed, and j is still equal 0, of course, j<n, and it ran to TLE
So check your algorithm again.
Notes: I have used “bits/stdc++.h” sometimes, but my advice for you: It’s not good to use nonstandard library for C++, it will be judged as “runtime error” on many judger, such as Codeforces, SPOJ.
Good luck
Sorry for my bad English
Here is my code for that problem, which is Accepted My code is seem to be clear, and I hope that will help you