C++ | 100% | Easiest | O(n+m)
IntuitionThe problem requires finding the distinct elements in each of the two arrays that are not present in the other array. My initial thought is to use hash
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires finding the distinct elements in each of the two arrays that are not present in the other array. My initial thought is to use hash maps to efficiently track the presence of elements in both arrays and then identify the unique elements for each array.


# Approach
<!-- Describe your approach to solving the problem. -->
- Use Hash Maps: Create two hash maps (mp1 and mp2) to store the frequency of elements in nums1 and nums2, respectively.

- Populate Hash Maps: Iterate through nums1 and nums2 to populate the hash maps with the counts of each element.

- Identify Unique Elements: Iterate through the keys in mp1 and check if they are not present in mp2. Similarly, iterate through the keys in mp2 and check if they are not present in mp1.

- Store Results: Store the unique elements for nums1 in ans1 and for nums2 in ans2.

- Return Result: Return the results as a vector of vectors containing ans1 and ans2.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n+m)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n+m)

# Code
```cpp []
class Solution {
public:
    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {
        vector<vector<int>> ans;
        unordered_map<int, int> mp1, mp2;
        int n1=nums1.size();
        int n2=nums2.size();
        for(int i=0; i<n1; i++){
            mp1[nums1[i]]++;
        }
        for(int i=0; i<n2; i++){
            mp2[nums2[i]]++;
        }
        vector<int> ans1, ans2;
        for(auto it: mp1){
            if(!mp2[it.first]){
                ans1.push_back(it.first);
            }
        }
        for(auto it: mp2){
            if(!mp1[it.first]){
                ans2.push_back(it.first);
            }
        }
        ans.push_back(ans1);
        ans.push_back(ans2);
        return ans;
    }
};
```
['C++']