include <bits/stdc++.h>
using namespace std; define ll long long
int main() {
// your code goes here
int nt;
cin>>nt;
while(nt–){
long long int n;
cin>>n;
vectorv(n);
ll int flag=1;
for(int i=0;i<n;i++){
cin>>v[i];
if(!i)continue;
else if (i==n-1)flag= v[i]==v[0];
else flag = v[i]>=v[0];
}
if(!flag)cout<<“NO”<<endl;
else cout<<“YES”<<endl;
}
return 0;
}
@ashu3208
plzz refer my c++ code for better understanding of the logic
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n ;
cin>>n;
int a[n];
int mn=INT_MAX;
for(int i=0;i<n;i++)
{
cin>>a[i];
mn=min(mn,a[i]);
}
if(a[0]==a[n-1]&&a[0]==mn)
cout<<"YES";
else
cout<<"NO";
cout<<endl;
}
return 0;
}
Hey,
My idea was same/similar but I couldn’t figure out why mine was not working.
But I got it now. The flag was getting updated each time, so I have to update flag only when it’s true