Greater element-wrong answer

include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];

	for(int i=0;i<n;i++)
	cin>>arr[i];

	int val=arr[0];
	for(int i=0;i<n;i++)
	{
		if(val==arr[n])
		cout<<-1<<" ";
		else
		cout<<arr[i+1]<<" ";
		val++;
	}
	// arr[0]=val;
return 0;

}

Hey @vashishthkuntal.gajjar2019 it’s a circular array, you have to tell the output for circular array, for eg:
Input
5
6 8 0 1 3
Expected output for this is:
8 -1 1 3 6
Yours is for linear array.
Hint: try to use stack in this.

include #include using namespace std; int main() { int n; cin>>n; int a[10000]; for(int i=0;i<n;i++) cin>>a[i]; stack s; s.push(a[0]); for(int i=1;i<n;i++){ while(!s.empty()&&s.top()<a[i]){ cout<<a[i]<<" β€œ; s.pop(); } s.push(a[i]); } while(!s.empty()) { cout<<-1<<” "; s.pop(); } }

one failed test case

Hey @vashishthkuntal.gajjar2019 check for this
4
8 2 3 6
Expected output is:
-1 3 6 8
Yours is not giving as per this order.

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.