My issue
For the problem statement:Array Halves Practice Coding Problem - CodeChef
Explain why the following logic is incorrect:
Please give a test case for which it will fail.
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int T;
cin>>T;
for(int t=0;t<T;t++)
{
long long int n;
cin>>n;
vector<long long int> a(2*n);
long long int cnt=0,ans=0;
for(int i=0;i<2*n;i++)
{
cin>>a[i];
if(a[i]>n) cnt++;
else ans+=cnt;
}
cout<<ans<<endl;
}
return 0;
}
Learning course: 1400 to 1600 difficulty problems
Problem Link: Array Halves Practice Problem in - CodeChef