question https://www.spoj.com/problems/STPAR/

solution - https://www.codechef.com/viewsolution/26226767

i am getting tle everytime please help me in optimising this solution

question https://www.spoj.com/problems/STPAR/

solution - https://www.codechef.com/viewsolution/26226767

i am getting tle everytime please help me in optimising this solution

Let, **N** be the number which is next in fixed order.

Take an input **X** , if it is equal to **N** then next number will be N++. If not, then search for **N** in the side lane and after finishing the search, put **X** in the side lane.

After all **X** is processed but **N** is not found in either **X** or side lane, then the order is not possible.

1 Like

Also there will be multiple testcase and zero will be present after only last testcase. so do take care for that. for ex :

int t;

while(scanf("%d",&t) && t!=0)

{

}

The input format seem to be mess up.

P.S : i checked your code and i guess you got logic wrong. Here’s simple explanation http://code.cloudkaksha.org/spoj/spoj-stpar-solution

1 Like