Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
9,686 views

All past online assesments of Virtusa can be found using the tag "virtusa_oa" in the search bar.

Here is the link : https://www.desiqna.in/tag/virtusa_oa

in Online Assessments by Expert (34,270 points) | 9,686 views

1 Answer

0 like 0 dislike
Best answer

 

#include <bits/stdc++.h>
using namespace std ; 
typedef long long int ll ; 

int main()
{
    ll n ; 
    cin>>n ; 
    vector <ll> a ;
    ll i = 0 ; 
    while(i<n)
    {
        ll x ;
        cin>>x;
        a.push_back(x);
        i++;
    }
    map<pair<ll,ll>,ll> q ; 
    ll k ; 
    cin>>k ; 
    ll j = 0 ; 
    i = 0 ;
    while(i<=n-1)
    {
        j = i + 1 ; 
        while(j<=n-1)
        {
            ll diff = abs(a[i]-a[j]);
            if(diff==k)
            {
                ll x1 = min(a[i],a[j]);
                ll y1 = max(a[i],a[j]);
                q[{x1,y1}]++;
            }
            j++;
        }
        i++;
    }
    ll answer = q.size();
    cout<<answer ; 
    return 0;
}

by Expert (34,270 points)
selected by