C++| Trie | Handwrittten | Easy to understand. :)
\n\n\nint cnt = 0;\nclass Solution {\npublic:\n    struct Trie {\n    unordered_map<int, Trie*> ch;\n    \n    void insert(vector<int>& nums, int i, int k, int 
![image](https://assets.leetcode.com/users/images/8b265852-f6e2-402d-8741-dd47859dc27c_1651482371.788373.png)\n\n```\nint cnt = 0;\nclass Solution {\npublic:\n    struct Trie {\n    unordered_map<int, Trie*> ch;\n    \n    void insert(vector<int>& nums, int i, int k, int p) {\n        if (i == nums.size() || k - (nums[i] % p == 0) < 0)\n            return ;\n        if (ch[nums[i]] == nullptr) {\n           ch[nums[i]] = new Trie();\n          cnt++;\n        }\n        ch[nums[i]]->insert(nums, i + 1, k - (nums[i] % p == 0), p);\n    }\n};\nint countDistinct(vector<int>& nums, int k, int p) {\n    cnt = 0;\n    Trie t;\n    for (int i = 0; i < nums.size(); ++i)\n        t.insert(nums, i, k, p);\n    return cnt;\n}\n};\n```\nThis post is an attempt to explain @doppler comment on the post: \nhttps://leetcode.com/problems/k-divisible-elements-subarrays/discuss/1996294/O(n-2)%3A-Rabin-Karp-vs.-Trie\n\nHope it helps someone. Any corrections or suggestions are welcomed. :)
[]