Pls help me with the logic
Divyam, try to solve this question using stack , rather than queues,You can refer to the approach below,
Take a stack of integers and then push 1st element into the stack, and then perform the loop from 1st element onwards and check
if(s.empty())
{
s.push(ar[i]);
continue;
}
while(!s.empty() && s.top()<ar[i])
{
cout<<ar[i]<<" ";
s.pop();
}
s.push(ar[i]);
This is the basic approach you can follow,