Python 5-Liner || Binary Search || Prefix Sum
\n5-Liner:\npy\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        pref_sum,l,s,sol=list(accumulate(nums2:=[int(x%p=
\n5-Liner:\n```py\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        pref_sum,l,s,sol=list(accumulate(nums2:=[int(x%p==0) for x in nums])),len(nums),set(),0\n        for left,x in enumerate(pref_sum):\n            for end in range(left+1,bisect_left(pref_sum,x+k if nums2[left] else x+1+k ,lo=left)+1):\n                if (t:=tuple(nums[left:end])) not in s:s.add(t)\n        return len(s)\n\n```\n\nExpanded Code :\n```py\nclass Solution:\n    def countDistinct(self, nums: List[int], k: int, p: int) -> int:\n        nums2 = [int(x % p == 0) for x in nums]\n        pref_sum = list(accumulate(nums2))\n        l = len(pref_sum)\n        s = set()\n        sol = 0\n        for left, x in enumerate(pref_sum):\n            if nums2[left] == 1:\n                tar = x + k\n            else:\n                tar = x + 1 + k\n            right = bisect_left(pref_sum, tar, lo=left)\n            for end in range(left + 1, right + 1):\n                t = tuple(nums[left:end])\n                if t not in s:\n                    s.add(t)\n        return len(s)\n```\n\n**Happy Coding !!**
['Binary Tree', 'Prefix Sum', 'Python']