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

 

in Online Assessments by Expert (108,110 points) | 1,287 views

2 Answers

0 like 0 dislike

   vector<int> arr = {1, 3, 5, 7, 1};

    int tar = 2;

    unordered_map<int, int> map;

    for(int i : arr) map[i]++;

 

    int ans = 0;

    for(auto it : map) {

        if(tar == 0) {

            if(it.second > 1) ans++;

        }

        else if(map.find(tar+it.first) != map.end()) ans++;

    }

    cout<<ans<<'\n';

by (160 points)
0 like 0 dislike
Example. ->

5

1 5 3 4 2

2

3
by Expert (108,110 points)
0 0
using hashmap we can do this