Similar Problems + Hints | Beats 99% | Clean Code
Similar Problem:\nIf you have premium you should definately solve this one after you\'ve solved the current problem.\n\n1198. Find Smallest Common Element in Al
# Similar Problem:\nIf you have premium you should definately solve this one after you\'ve solved the current problem.\n\n[1198. Find Smallest Common Element in All Rows (Premium)](https://leetcode.com/problems/find-smallest-common-element-in-all-rows/description/)\n\n# Hints:\n\nClick to open the hints. Try it yourself!\n\n<details open>\n  <summary>Hint 1</summary>\n  Notice that each row has no duplicates.\n</details>\n<br>\n<details>\n  <summary>Hint 2</summary>\n    Is counting the frequency of elements enough to find the answer?\n</details>\n<br>\n<details>\n  <summary>Hint 3</summary>\n    Use a data structure to count the frequency of elements.\n</details>\n<br>\n<details>\n  <summary>Hint 3</summary>\n    Iterate for each element in freqMap array. Find an element whose frequency equals the number of rows.\n</details>\n\n# Code\n``` java []\nclass Solution {\n    public List<Integer> intersection(int[][] nums) {\n        int ROW = nums.length;\n        int M = 1001;\n        int[] freq = new int[M];\n        for(int i=0; i<ROW; i++) {\n            for(int j=0; j<nums[i].length; j++) {\n                int num = nums[i][j];\n                freq[num]++;\n            }\n        }\n        List<Integer> ans = new ArrayList<>();\n        for(int i=1; i<M; i++) {\n            if(freq[i] == ROW) {\n                ans.add(i);\n            }\n        }\n        return ans;\n    }\n}\n```\n![image.png](https://assets.leetcode.com/users/images/81fc4b03-259b-4d59-983d-2d4028276d0d_1693771202.2572947.png)\n
['Array', 'Counting', 'Java']