C++ || O(N^2) |
Intuition\nsince the time complexity of the given problem can go to N^2, we can easily track all the subarrayys with the given conditions.\n# Approach\nJust kee
# Intuition\nsince the time complexity of the given problem can go to N^2, we can easily track all the subarrayys with the given conditions.\n# Approach\nJust keep pusing the elements in set of strings if the conditions are satisfied, finally we return the distinct non-empty subarrays by size fo the set\n# Complexity\n- Time complexity:\nO(N^2)\n- Space complexity:\nO(Set elements)\n# Code\n```\nclass Solution {\npublic:\n    int countDistinct(vector<int>& a, int k, int p) {\n        \n        // we can use hashmap: with a[i] = 1 if divisible by p else 0.\n        int n = a.size(), ans = 0;\n        unordered_set<string>s;\n        for(int i=0;i<n;i++){\n          int cnt = 0;\n          string temp = "";\n          for(int j = i; j < n; j++){\n            //  cnt += (a[j]%p == 0) ? 1 : 0;\n            if(a[j]%p == 0) cnt++;\n             if(cnt <= k) { temp += a[j]; s.insert(temp);}\n             if(cnt>k)break;\n          }\n          // s.insert(temp);\n        }\n        return s.size(); // count of distinct sets.\n\n    }\n};\n```
['C++']