Intersection of Multiple Arrays
Intuition\nThe goal is to find elements that appear in every array. To achieve this, we can use a HashMap to count the occurrences of each element across all ar
# Intuition\nThe goal is to find elements that appear in every array. To achieve this, we can use a HashMap to count the occurrences of each element across all arrays. Once we know the frequency of each element, we can check which elements appear in every array and return them as the intersection.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUse a HashMap:\n- We traverse each array and for each element, we update its count in the HashMap.\n- The key in the map is the element, and the value is the count of how many arrays it appears in.\n\nFilter Common Elements:\n- After counting, we check the map. If an element\'s count equals the number of arrays (nums.length), it means the element is present in all arrays.\n\nSort the Result:\n- The elements that are common in all arrays are then added to a list and sorted.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nTime complexity: O(n * m), where n is the number of arrays, and m is the average length of each array. We iterate through every element once while counting and sorting.\n\n\n- Space complexity:\n\nSpace complexity: O(m), where m is the number of unique elements across all arrays. This space is used by the HashMap to store the count of each element.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public List<Integer> intersection(int[][] nums) {\n        Map<Integer, Integer> map = new HashMap<>();\n        List<Integer> list = new ArrayList<>();\n\n        int n = nums.length;\n        for (int[] num : nums) {\n            for (int i = 0; i < num.length; i++) {\n                map.put(num[i], map.getOrDefault(num[i], 0) + 1);\n            }\n        }\n        for (Integer key : map.keySet()) {\n            if (map.get(key) == nums.length) {\n                list.add(key);\n            }\n        }\n        Collections.sort(list);\n        return list;\n    }\n}\n```
['Array', 'Hash Table', 'Sorting', 'Java']