Sliding Window Technique: O(N^2)
Intuition\nSince the problem is about subarrays, I felt like the sliding window method is great at dealing with subarrays.\n\n# Approach\nWe\'re gonna run throu
# Intuition\nSince the problem is about subarrays, I felt like the sliding window method is great at dealing with subarrays.\n\n# Approach\nWe\'re gonna run through the list with two pointers, i and j. They both start at the beginning, but we keep moving j ahead until we hit more than k numbers in the nums[i:j+1] section that can be divided by p. Every time we find a section that fits the requirements, we add it into a set. Once we can\'t push j any more without breaking the rules, we increase i up a spot and repeat the process.\n\n# Complexity\n- Time complexity: O(N^2)\nThe sliding window approach goes through the list twice, once for each "start" point and once for each "end" point of a subarray. Since we\'re looping twice for each item in the list, we say it takes O(N^2).\n\n- Space complexity: O(N)\nThe main thing taking up extra space is the set where we keep track of the subarrays. Given we might end up storing a bunch of subarrays in the set, and each subarray can be as big as the original list, our space usage can be roughly proportional to the size of the list, making it O(N).\n\n# Code\n```\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        res = set()\n        N = len(nums)\n\n        for i in range(N):\n            count = 0\n\n            for j in range(i, N):\n                if nums[j] % p == 0:\n                    count += 1\n                if count > k:\n                    break\n                \n                res.add(tuple(nums[i:j + 1]))\n\n        return len(res)\n```
['Sliding Window', 'Python3']