Hash Map Solution - Beats 100% Runtime
IntuitionThe problem asks to find the intersection of multiple lists of integers. The goal is to identify the elements that are common to all the lists.A good a
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem asks to find the intersection of multiple lists of integers. The goal is to identify the elements that are common to all the lists.

A good approach to this problem is to count the frequency of each element across all the lists. If an element appears in every list, then it is part of the intersection. This can be achieved using a dictionary (hashmap) to store the frequency of each element. If an element appears in every list (i.e., the frequency is equal to the number of lists), it belongs to the intersection.

# Approach
<!-- Describe your approach to solving the problem. -->
1.	Initialization: Start by creating a dictionary, ref, to store the frequency of each element across all the lists.
2.	Iterate through each list: For each list in the nums input, iterate through its elements and count how many times each element appears across the lists. This can be done by updating the count of each element in the dictionary.
3.	Check frequency: Once the dictionary is populated, iterate over the dictionary to check which elements have a frequency equal to the number of lists. These are the elements that are present in every list.
4.	Sort the result: The result needs to be sorted before returning, as the problem might require the intersection to be in ascending order.
5.	Return the result: The result will be the list of elements that are common in all the input lists, sorted in ascending order.


# Complexity
- Time complexity: We iterate over each list and each element in the list, which gives a time complexity of O(m * n), where m is the number of lists and n is the average size of the lists. After building the frequency map, we need to check the dictionary, which takes O(k) time, where k is the number of unique elements in the input lists. Sorting the final result will take O(k log k) time.
Hence, the total time complexity is: O(m * n + k log k).

<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: The space required for the frequency dictionary is proportional to the number of unique elements across all the lists. In the worst case, this could be all the elements across all lists, giving a space complexity of O(k).
![Intersection-Of-Multiple-Arrays.png](https://assets.leetcode.com/users/images/2df741d7-a73e-47e2-8731-dc4c9f2952fe_1737554638.3748608.png)
We also use additional space for storing the result, which could have at most k elements.
Hence, the space complexity is: O(k).

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

# Code
```python3 []
class Solution:
    def intersection(self, nums: List[List[int]]) -> List[int]:
        # Initialize a dictionary to store the frequency of each element
        ref = {}

        # Iterate over each list in the input
        for i in range(len(nums)):
            row = nums[i]  # Get the current list
            # Iterate over each element in the current list
            for n in row:
                if n in ref:
                    # If element is already in the dictionary, increment its count
                    ref[n] += 1
                else:
                    # If element is not in the dictionary, initialize its count to 1
                    ref[n] = 1
        
        # List to store the intersection result
        res = []

        # Iterate through the dictionary to find elements that appear in all lists
        for key, value in ref.items():
            if value == len(nums):  # If the element appeared in all lists
                res.append(key)
        
        # Return the sorted list of common elements
        return sorted(res)



        
```
['Python3']