https://ide.geeksforgeeks.org/tVNmIY25dP
failing some test cases
Find the greater element-stacks,queue,deque
Hey @anitagupta1411
#include<iostream>
using namespace std;
void nextgreater(int* a,int n){
for(int i=0;i<n;i++)
{
int j=(i+1)%n; //updated
while(j!=i) //updated
{
if(a[j]>a[i]){
cout<<a[j];
if(i!=(n-1)){
cout<<" ";
}
break;
}
j=(j+1)%n;
}
if(j==i){ //updated
cout<<"-1";
if(i!=(n-1)){
cout<<" ";
}
}
}
}
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
nextgreater(a,n);
return 0;
}
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.