One of the testcases is not succeeding in this code

#include <bits/stdc++.h>
using namespace std;

void next_greater(vectora,int n){
vector v;
stack s;
s.push(-1);

for(int i = n -1; i>= 0; i--){
	while(s.top() <= a[i] && s.top() != -1){
		s.pop();
	}
	v.push_back(s.top());
	s.push(a[i]);
}

for(int i = n-1; i>=0; i--){
	cout << v[i] << " ";
}

}

int main() {
int n;
cin >> n;
vectora;
for( int i = 0; i <n; i++){
int no;
cin >> no;
a.push_back(no);
}
next_greater(a,n);
return 0;
}

hi @akki56756_bab14f919dbad123, please share your code here : https://ide.codingblocks.com/

@akki56756_bab14f919dbad123,
its a circular array
for input :
4
8 2 3 6
ans is -1 3 6 8 but your code says -1 3 6 -1 as its circular so next greater of 6 will be 8

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.