Intersection of two arrays

PHOTO EMBED

Sun Oct 09 2022 17:56:31 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
  public:
    // Function to return the count of the number of elements in
    // the intersection of two arrays.
    int NumberofElementsInIntersection(int a[], int b[], int n, int m) {
        // Your code goes here
        unordered_map<int,int> s,t;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            s[a[i]]++;
        }
        for(int i=0;i<m;i++)
        {
            t[b[i]]++;
        }
        for(auto x:s)
        {
            if(t.count(x.first)>0)
            {ans++;}
        }
        return ans;
    }
};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/intersection-of-two-arrays2404/1?page=1&company[]=PayPal&sortBy=submissions