Amazon OA Question
Anonymous User
940

Given n ,c,d and two arrays a and b each of length n
count number of pairs satisfying the following condition
a[i]-a[j]+c<=b[i]-b[j]+d

n<=10^5

//brute force solution

int ans=0;
for(int i=0;i<n;i++)
{
    for(int j=i+1;j<n;j++)
    {
        if(a[i]-b[i]+c<=a[j]-b[j]+d)
        {
            ans++;
        }
    }
}
cout<<ans<<endl;

passed 5 testcases out of 10

Comments (6)