My issue
Whats wrong in my code for the test case ?
1
5
1 1 4 3 1
how can i modify my code ?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int x;
vector<pair<int,int>>p;
for(int i=0;i<n;i++)
{
cin>>x;
p.push_back(make_pair(x, i));
}
sort(p.begin(), p.end());
bool ok=true;
int cnt=0;
int y=-1;
for(int i=0;i<n-1;i++)
{
if(p[i].second>p[i+1].second && p[i].first!=y)
{
cnt++;
y=p[i+1].first;
}
if(cnt>1)
{
ok=false;
break;
}
}
cout<<(ok ? "YES" : "NO")<<endl;
}
}
Learning course: 1600 to 1800 difficulty problems
Problem Link: Concat Sort Practice Problem in - CodeChef