Need help,Getting WA in problem Street Parade of SPOJ.

Problem Link : http://www.spoj.com/problems/STPAR/

I have tried debugging my code but i am unable to find the error. Please Help.!!

My Actual Solution Link: http://ideone.com/kJ6rDr

Modified Solution Link [with multiple random generated test cases] : http://ideone.com/kECT3L

My Pseudo-code :

Getting Input

for i from 1 to top:   //top=size of array;

    for j from k to top:
         Checking if stack[j] == i:
              If true j++ ,k=j and break

         Else Check queue[index]==i:
              if true index-- and break

         Else enqueue stack[j] at queue[++index]:
              Check whether queue[index]>queue[index-1]:
                   if true break and print no
    

Please Help!!

Understand the input format correctly. It is something of this kind…

read(N)
while N is not 0
    read Array
    // your code here
    read(N)

You are not given number of test cases. Test file ends with N = 0 where you should terminate your code.

1 Like

With this test:

5

1 2 3 4 5

5

5 4 3 2 1

0

What is your answer? It got TLE :slight_smile: because you read wrong integer. No number of tests are given in test, but if you read “love of mobiles” is equal 0, it will terminate :slight_smile:

I have answered the question about this problem before. Here is my algorithm for that problem:

Let assume x is current number, and we have one stack stores a “love mobiles” which couldn’t be in-ordered at sometimes.

If stack[top]=x, then pop it from stack and increase x by one. Repeat that process until stack[top]<>x or stack is empty.

If x=a[i], then increase x by one, else push it into stack. Actually, increase i. Repeat that process until (i or i) >number of love mobiles.

If we can’t do any process above, and x is not exceed number of love mobiles, we output “no”, else “yes”.

Here is my sample solution for that problem: #12991927 on SPOJ

1 Like

Seems i misunderstood the question…

Thanks @vinayawsm for pointing that out…
But still have some confusions, which i have mentioned in @leduongtuananh 's comment…

Can you please Explain…

Thanks… :slight_smile:

Now i am bit confused about the input and output…

Hey @leduongtuananh

Can you please explain me what will be the output for this test case

5
5 4 3 2 1
3
3 2 1
0

Please… !!

Yes for both the cases.
Explanation for 2nd case…

3
3 2 1

3 enters side street.
2 enters side street.
1 moves to other side.
2 moves to other side.
3 moves to other side.

They are in order now.

1 Like

okay so you mean those were two different cases…

I thought that we have to take both into consideration to solve a single test case…:slight_smile:

Now i got it… Thanks…:slight_smile: