My testcase 4 isfailing..pls tell me what i am doing wrong

Hello @angivanshikaangi,

Observe the following picture carefully:
image

You have missed the case of S5 and S6.
Let’s understand with an example:
5
2 3 4 2 5
Your Output:
1 2 3 1 2 END
Expected Output:
1 2 3 1 5 END

Hope, this would help.
Give a like, if you are satisfied.

pls tell what editing i need to do in code

@angivanshikaangi,

I have checked your code, the way you are using stack is inappropriate and would not produce the desire output.
reasons:

  1. The else part of your code would always print 1 irrespective of the number of elements in the stack.
  2. If you would pop all elements of stack, then the stack will become empty, thus o reaching 5, it will contain only 2 elements and will print 2, though answer should be 5
  3. Similarly if would not pop elements, then it would always print 5.

Solution:
Refer to the following segment of the code:

Read the comments for better understanding.

Hope, this would help.
Give a like, if you are satisfied.