Java | Optimised Solution | HashMap + ArrayList
A variation of : https://leetcode.com/problems/number-of-good-pairs/\n\n\nclass Solution {\n    public int countPairs(int[] nums, int k) {\n      HashMap<Intege
A variation of : https://leetcode.com/problems/number-of-good-pairs/\n\n```\nclass Solution {\n    public int countPairs(int[] nums, int k) {\n      HashMap<Integer,List<Integer>> hMap = new HashMap<>();\n        int count = 0;\n        for(int i = 0 ; i < nums.length ; i++){\n            if(!hMap.containsKey(nums[i])){\n                List<Integer> l = new ArrayList<>();\n                l.add(i);\n                hMap.put(nums[i],l);\n            }else{\n                List<Integer> v = hMap.get(nums[i]);\n                for(Integer j : v){\n                    if((i*j)%k == 0) count++;\n                }\n                v.add(i);\n                hMap.put(nums[i],v);                \n            }\n        }\n        return count;\n    }\n}\n```
['Java']