Bitmask DP + Digit DP | C++ 17ms Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\n    int dp[(1<<10)+1][10][2][2][2];\npublic:\n    int solve(string &str, int i, bool tight, bool ok, bool is, int mask,\n             int dp[(1<<10)+1][10][2][2][2]){\n        if(i == str.size()) return ok;\n        if(dp[mask][i][tight][ok][is] != -1) return dp[mask][i][tight][ok][is];\n        int ans = 0;\n        if(tight){\n           for(char ch=\'0\';ch<=str[i];ch++){\n              if(!is && (ch == \'0\')){\n                ans += solve(str,i+1,(ch==str[i]),0, 0, 0,dp);\n              }\n              else {\n                int z = ch-\'0\';\n                ans += solve(str, i+1,(ch==str[i]), (ok | (mask&(1<<z))), 1, mask | (1<<z),dp);\n              }\n           }\n        }\n        else{\n            for(char ch=\'0\';ch<=\'9\';ch++){\n              if(!is && (ch == \'0\')){\n                ans += solve(str, i+1,0, 0, 0, 0, dp);\n              }\n              else {\n                int z = ch-\'0\';\n                ans += solve(str, i+1, 0, (ok | mask&(1<<z)), 1, mask | (1<<z), dp);\n              }\n            }\n        }\n        return dp[mask][i][tight][ok][is] = ans;\n    }\n    int numDupDigitsAtMostN(int n) {\n        string str = to_string(n);\n        memset(dp, -1, sizeof(dp));\n        return solve(str, 0, 1, 0, 0, 0, dp);\n    }\n};\n```
['Dynamic Programming', 'C++']