✅ [c++]  || Digit DP with Bismasking ||  recursive+memoization
\nclass Solution {\npublic:\n    \n    int dp[11][2][1024][2]; //dp[pos][strictly][s][repeated]\n    //s value can go upto 1024.\n    //logic:- if we set all bi
```\nclass Solution {\npublic:\n    \n    int dp[11][2][1024][2]; //dp[pos][strictly][s][repeated]\n    //s value can go upto 1024.\n    //logic:- if we set all bit from (9...0) it gives approx. 1023 \n    int solve(string& str, int pos, bool strictly, int s, bool repeated){\n        if(pos==str.size()){\n            if(repeated) return 1;\n            else return 0;\n        }\n        if(dp[pos][strictly][s][repeated]!=-1) return dp[pos][strictly][s][repeated];\n        int cur=0, n=str[pos]-\'0\';\n        if(strictly){\n            for(int i=0;i<=n;++i){\n                if(i==0 and s==0) cur+=solve(str,pos+1,false,s,repeated); //leading zero\n                else if(i==n){\n                    if(s&(1<<i)) cur+=solve(str,pos+1,true,s,true);\n                    else cur+=solve(str,pos+1,true,s^(1<<i),repeated);\n                }else{\n                    if(s&(1<<i)) cur+=solve(str,pos+1,false,s,true);\n                    else cur+=solve(str,pos+1,false,s^(1<<i),repeated);\n                }\n            }\n        }else{\n            for(int i=0;i<=9;++i){\n                if(i==0 and s==0) cur+=solve(str,pos+1,false,s,repeated); //leading zero\n                else{\n                    if(s&(1<<i)) cur+=solve(str,pos+1,false,s,true);\n                    else cur+=solve(str,pos+1,false,s^(1<<i),repeated);\n                }\n            }\n        }\n        return dp[pos][strictly][s][repeated] = cur;\n    }\n    \n    \n    int numDupDigitsAtMostN(int n) {\n        string str = to_string(n);\n        memset(dp,-1,sizeof(dp));\n        return solve(str,0,true,0,false);\n    }\n};\n```\nPlease **UPVOTE**
['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'Bitmask', 'C++']