BEATS 100% of users✅ || Goldman Sachs⭐ || Easy✔️ || Challenge🏆
"Your thoughts are welcome! \uD83D\uDCAD"\n\n\n#ReviseWithArsh #6Companies30Days challenge 2k24*\nCompany 1 :- Goldman Sachs\n\n### CODE\nCPP []\nclass Solution
> ***"Your thoughts are welcome! \uD83D\uDCAD"***\n\n\n***```#ReviseWithArsh #6Companies30Days challenge 2k24```**\n**`` Company 1 :- Goldman Sachs ``***\n\n### CODE\n```CPP []\nclass Solution {\npublic:\n    static const int BASE = 397; // Base for rolling hash\n    static const long long MOD = 100000000069; // Modulo to prevent overflow\n\n    int countDistinct(std::vector<int>& nums, int maxOnes, int moduloFactor) {\n        std::vector<int> isDivisible(nums.size()); // 1 if divisible by moduloFactor, else 0\n        std::transform(nums.begin(), nums.end(), isDivisible.begin(),\n                       [moduloFactor](int x) { return x % moduloFactor == 0 ? 1 : 0; });\n\n        std::unordered_set<long long> distinctHashes;\n\n        for (int start = 0; start < nums.size(); ++start) {\n            int onesCount = 0; // Count of elements divisible by moduloFactor in the current subarray\n            long long hashValue = 0; // Rolling hash value for the current subarray\n\n            for (int end = start; end < nums.size() && onesCount <= maxOnes; ++end) {\n                // Update the rolling hash value\n                hashValue = (hashValue * BASE + nums[end] + (end + 1 - start)) % MOD;\n\n                // Update the count of elements divisible by moduloFactor\n                onesCount += (isDivisible[end] == 1);\n\n                // Add the hash value to the set if the count of divisible elements is within the limit\n                if (onesCount <= maxOnes) {\n                    distinctHashes.insert(hashValue);\n                } else {\n                    // Break the loop if the count exceeds the limit\n                    break;\n                }\n            }\n        }\n\n        // Return the count of distinct hash values\n        return distinctHashes.size();\n    }\n};\n\n```\n\n*Let\'s collaborate! Join me on GitHub to work on this challenge together* :- \n*[https://github.com/nandini-gangrade/6Companies30Days](GITHUB)*\n\n> ***Happy Coding \uD83D\uDCBB***
['C++']