Simplest and Easiest Solution Ever 🔥+Video Solution🏆 | C++ | O(1) Space | Brute-Force
Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to find common elements between two arrays and count their occurrences in e
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to find common elements between two arrays and count their occurrences in each array.\nTwo values need to be calculated: the count of elements in nums1 that occur in nums2 and the count of elements in nums2 that occur in nums1.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize variables: n as the size of nums1, m as the size of nums2, and ans as a vector of size 2 to store the results.\n2. Use nested loops to iterate through each element of nums1 and nums2.\n3. In the first loop, check if the current element of nums1 is equal to any element in nums2. If yes, increment the first value in ans.\n4. In the second loop, check if the current element of nums2 is equal to any element in nums1. If yes, increment the second value in ans.\n5. Return the computed ans vector containing the counts of common elements in the specified order.\n\nhttps://youtu.be/rO-odwo8Ecw\n\n# Complexity\n- Time complexity: O(n*m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> findIntersectionValues(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size();\n        int m = nums2.size();\n        vector<int> ans(2);\n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(nums1[i]==nums2[j]){\n                    ans[0]++;\n                    break;\n                }\n            }\n        }\n        for(int i=0; i<m; i++){\n            for(int j=0; j<n; j++){\n                if(nums1[j]==nums2[i]){\n                    ans[1]++;\n                    break;\n                }\n            }\n        }\n        return ans;\n        \n    }\n};\n```
['Array', 'C++']