Easy to understand || Recursion || Generate all Subarrays
\n/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number} p\n * @return {number}\n */\nvar countDistinct = function(nums, k, p) {\n    \n    le
```\n/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number} p\n * @return {number}\n */\nvar countDistinct = function(nums, k, p) {\n    \n    let ans = new Set();\n    let temp = [];\n    let hash = {};\n    function solve(nums, k, p, ind, cnt, str) {    \n        if (cnt > k || (temp.length >= 2 && temp[temp.length-2]+1 != temp[temp.length-1])) {\n            return;\n        }\n        \n        if (str.length > 0 && cnt <= k) {\n            ans.add(str);\n        }\n        \n        for (let i = ind; i < nums.length; i++) {\n            temp.push(i);\n            solve(nums, k, p, i+1, (nums[i] % p == 0) ? cnt + 1 : cnt, str+"~"+nums[i]);\n            temp.pop();\n        }\n    }\n    \n    solve(nums, k, p, 0, 0, "");\n    return [...ans].length;\n};\n```
['String', 'Recursion', 'Ordered Set', 'JavaScript']