Naive brute force | Find all subarrays | Clear Comments
\nclass Solution {\n    public int countDistinct(int[] nums, int k, int p) {\n        HashSet<String> hs = new HashSet<>();\n        // Traverse arrays\n       
```\nclass Solution {\n    public int countDistinct(int[] nums, int k, int p) {\n        HashSet<String> hs = new HashSet<>();\n        // Traverse arrays\n        for(int i=0;i<nums.length;i++){\n            String s ="";\n            int c =0;\n            //Calculate subarrays\n            for(int j=i;j<nums.length;j++){\n                // Generate unique string for integer value, apply any hash mechanism to optmise\n                s+=\'0\'+nums[j];\n                // Check divisible numbers\n                if(nums[j]%p==0) c++;\n                if(c>k) break;\n                // If at most k divisible add in set\n                hs.add(s);\n            }\n        }\n        return hs.size();\n    }\n}\n```
['Java']