✅C++ || EXPLAINED || BEATS 100% || OPTIMIZED
PLEASE UPVOTE IF YOU FIND MY APPROACH HELPFUL, MEANS A LOT \uD83D\uDE0A\n\nExplanation:\n\n Initialize an ordered map mp and vector vec.\n\n Traverse the 2D arr
**PLEASE UPVOTE IF YOU FIND MY APPROACH HELPFUL, MEANS A LOT \uD83D\uDE0A**\n\n**Explanation:**\n\n* Initialize an ordered map mp and vector vec.\n\n* Traverse the 2D array and store the elements present with their frequency.\n* Now check if the element.second (frequency) stored in the map is equal to the no. of rows in the array.\n* If element.second == no. of rows then it implies that the element is present in every array.\n* Push all the elements which satisfy this condition.\n* Return the vector vec as it now contains the intersecting elements.\n\n```\nclass Solution {\npublic:\n    vector<int> intersection(vector<vector<int>>& nums) {\n        int n = nums.size(); // gives the no. of rows\n        map<int,int> mp; // we don\'t need unordered_map because we need the elements to be in sorted format.\n        vector<int> vec;\n        \n        // traverse through the 2D array and store the frequency of each element\n        for(int row=0;row<n;row++)\n        {\n            for(int col=0;col<nums[row].size();col++)\n            {\n                mp[nums[row][col]]++;\n            }\n        }\n        \n        // In the 2D array, intersection occurs when the elements are present in every row.\n        // So the frequency of the element should match with the no. or rows in the 2D array.\n        for(auto element : mp)\n            if(element.second == n)\n                vec.push_back(element.first);\n        \n        // return the intersecting elements\n        return vec;\n    }\n};\n```\n
['C', 'C++']