My issue
Runtime Error
My code
#include <bits/stdc++.h>
using namespace std;
bool checkdiff(vector<int>&v,int size, int target)
{
sort(v.begin(),v.end());
int i=0,j=1;
while(i<j)
{
if(abs(v[i]-v[j])==target)
return true;
else if((v[j]-v[i]<target))
{
j++;
}
else{
i++;
}
}
return 0;
}
int main() {
int t; cin>>t;
while(t--)
{
int size; cin>>size;
int target; cin>>target;
vector<int> v;
for(int i=0;i<size;i++)
{
int x;
cin>>x;
v.push_back(x);
}
int ans=checkdiff(v,size,target);
cout<<ans<<endl;
}
return 0;
}
Learning course: Two pointers
Problem Link: CodeChef: Practical coding for everyone