I solved the problem by arrays.
Its is under stack section so please guide me through using stacks?
IS THIS PROBLEM DESIGNED specifically FOR STACKS?
@mohit_99 hey mohit our motto is basically to teach you the variation about the question if this problem are in stack section so you should try with it stacks.
so how this problem solve using stacks.
first take a input array
and a stack< int > s;
push the first index of array into the stack like s.push(a[0]);
apply loop from i=1 to n
now apply a while loop
while(!s.empty()&&s.top()<a[ i ])
{
cout<<a[ i ]<<" “;
now pop the current element from the stack reason for that we want to check for next element
s.pop();
}
push the next element of the array according to loop
s.push( a[ i ] );
while(! s.empty() )
{
cout<<-1<<” ";
s.pop();
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.