JAVA solution | O(n^2) | Hashset | Stringbuilder
Please Upvote !!! (\u25E0\u203F\u25E0)\n\nclass Solution {\n    public int countDistinct(int[] nums, int k, int p) {\n        Set<String> set = new HashSet<>();
### ***Please Upvote !!!*** **(\u25E0\u203F\u25E0)**\n```\nclass Solution {\n    public int countDistinct(int[] nums, int k, int p) {\n        Set<String> set = new HashSet<>();\n\n        for (int i = 0; i < nums.length; i++) {\n            int count = 0;\n            StringBuilder sb = new StringBuilder();\n\n            for (int j = i; j < nums.length; j++) {\n                if (nums[j] % p == 0) count++;\n                if (count > k) break;\n\n                sb.append(nums[j] + " ");\n                set.add(sb.toString());\n            }\n        }\n\n        return set.size();\n    }\n}\n\n// TC: O(n ^ 2), SC: O(n ^ 2)\n```
['String', 'Java']