Https://ide.codingblocks.com/s/327961

why test case 1 not corrrect

Hey @gagz23,
with an example i can tell you where your code is failing ,
Suppose you have : 8 1 2 7 elements in an array , when you are done with your for loop
for(int i=1;i<n;i++)

{  

    if(s.empty())

    s.push(i);

    while(s.empty()==false && arr[i]>arr[s.top()])

    {

        arr[s.top()]=arr[i];

        s.pop();

    }

    s.push(i);

}

the s.top() element you will be having is 3 and you are making arr[3]=-1,
which brings you an output of : -1 2 7 -1
instead it should give you : -1 2 7 8
hope it will help you to solve it.