✅☑[C++/Java/Python/JavaScript] || Easy Approach || EXPLAINED🔥
PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n\n\n\n1. It creates unordered sets set1 and set2 from nums1 and nums2 respect
# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n\n\n\n1. It creates unordered sets `set1` and `set2` from `nums1` and `nums2` respectively. These sets contain unique elements from the vectors, allowing faster lookup.\n\n1. Two counts, `count1` and `count2`, are initialized to track the intersections.\n\n1. It iterates through `nums1` and checks if each element exists in `set2`. If found, it increments `count1`.\n\n1. Similarly, it iterates through `nums2` and checks if each element exists in `set1`. If found, it increments `count2`.\n\n1. Finally, it returns a vector containing the counts of intersection for both vectors.\n\n\n# Complexity\n- *Time complexity:*\n   $$O(n)$$\n    \n\n- *Space complexity:*\n   $$O(m+n)$$\n    \n\n\n# Code\n```C++ []\n\n\nclass Solution {\npublic:\n    // Function to find intersection values between two vectors\n    std::vector<int> findIntersectionValues(std::vector<int>& nums1, std::vector<int>& nums2) {\n        // Create unordered sets from nums1 and nums2\n        std::unordered_set<int> set1(nums1.begin(), nums1.end());\n        std::unordered_set<int> set2(nums2.begin(), nums2.end());\n\n        int count1 = 0, count2 = 0;\n\n        // Find the number of elements in nums1 that are present in nums2\n        for (int num : nums1) {\n            if (set2.find(num) != set2.end()) {\n                count1++;\n            }\n        }\n\n        // Find the number of elements in nums2 that are present in nums1\n        for (int num : nums2) {\n            if (set1.find(num) != set1.end()) {\n                count2++;\n            }\n        }\n\n        // Return the counts of intersection for both vectors\n        return {count1, count2};\n    }\n};\n\n\n\n```\n```C []\n\n\nstruct Node {\n    int data;\n    struct Node* next;\n};\n\nstruct Node* createNode(int data) {\n    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));\n    newNode->data = data;\n    newNode->next = NULL;\n    return newNode;\n}\n\nint* findIntersectionValues(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) {\n    struct Node* set1 = NULL;\n    struct Node* set2 = NULL;\n\n    // Create sets from nums1 and nums2\n    for (int i = 0; i < nums1Size; i++) {\n        struct Node* newNode = createNode(nums1[i]);\n        newNode->next = set1;\n        set1 = newNode;\n    }\n\n    for (int i = 0; i < nums2Size; i++) {\n        struct Node* newNode = createNode(nums2[i]);\n        newNode->next = set2;\n        set2 = newNode;\n    }\n\n    int count1 = 0, count2 = 0;\n\n    // Find the number of elements in nums1 that are present in nums2\n    for (struct Node* curr = set1; curr != NULL; curr = curr->next) {\n        struct Node* temp = set2;\n        while (temp != NULL) {\n            if (temp->data == curr->data) {\n                count1++;\n                break;\n            }\n            temp = temp->next;\n        }\n    }\n\n    // Find the number of elements in nums2 that are present in nums1\n    for (struct Node* curr = set2; curr != NULL; curr = curr->next) {\n        struct Node* temp = set1;\n        while (temp != NULL) {\n            if (temp->data == curr->data) {\n                count2++;\n                break;\n            }\n            temp = temp->next;\n        }\n    }\n\n    int* result = (int*)malloc(2 * sizeof(int));\n    result[0] = count1;\n    result[1] = count2;\n    *returnSize = 2;\n    return result;\n}\n\n\n\n\n\n```\n```Java []\nimport java.util.*;\n\nclass Solution {\n    public int[] findIntersectionValues(int[] nums1, int[] nums2) {\n        Set<Integer> set1 = new HashSet<>();\n        Set<Integer> set2 = new HashSet<>();\n\n        for (int num : nums1) {\n            set1.add(num);\n        }\n\n        for (int num : nums2) {\n            set2.add(num);\n        }\n\n        int count1 = 0, count2 = 0;\n\n        for (int num : nums1) {\n            if (set2.contains(num)) {\n                count1++;\n            }\n        }\n\n        for (int num : nums2) {\n            if (set1.contains(num)) {\n                count2++;\n            }\n        }\n\n        return new int[]{count1, count2};\n    }\n}\n\n\n\n```\n```python3 []\nclass Solution:\n    def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]:\n        set1 = set(nums1)\n        set2 = set(nums2)\n\n        count1 = sum(1 for num in nums1 if num in set2)\n        count2 = sum(1 for num in nums2 if num in set1)\n\n        return [count1, count2]\n\n\n\n```\n```javascript []\n\nfunction findIntersectionValues(nums1, nums2) {\n    let set1 = new Set(nums1);\n    let set2 = new Set(nums2);\n\n    let count1 = 0, count2 = 0;\n\n    // Find the number of elements in nums1 that are present in nums2\n    for (let num of nums1) {\n        if (set2.has(num)) {\n            count1++;\n        }\n    }\n\n    // Find the number of elements in nums2 that are present in nums1\n    for (let num of nums2) {\n        if (set1.has(num)) {\n            count2++;\n        }\n    }\n\n    return [count1, count2];\n}\n\n\n```\n\n---\n\n\n\n# PLEASE UPVOTE IF IT HELPED\n\n---\n---\n\n\n---
['Array', 'C', 'C++', 'Java', 'Python3', 'JavaScript']