C++ | Digit Dp | Video Solution | 77% faster than others!
Digit Dp\n\n# Video Solution\n\nhttps://youtu.be/IKQSexsR7eE?si=5Mnk7J7MYc2YycON\n\n# Code\n\nclass Solution {\npublic:\n    int dp[11][2][1<<10][2];\n    int f
# Digit Dp\n\n# Video Solution\n\n[https://youtu.be/IKQSexsR7eE?si=5Mnk7J7MYc2YycON]()\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[11][2][1<<10][2];\n    int f(int i,string& s,int lz,int mask,int ise){\n        if(i==s.size()) return 1;\n        if(dp[i][lz][mask][ise]!=-1) return dp[i][lz][mask][ise];\n        int mxx=(ise)?(s[i]-\'0\'):9,ans=0;\n        for(int j=0;j<=mxx;j++){\n            if(lz==0 && (mask&(1<<j))) continue;\n            mask|=(1<<j);\n            ans+=f(i+1,s,lz&(j==0),mask,ise&(j==mxx));\n            mask^=(1<<j);\n        }\n        return dp[i][lz][mask][ise]=ans;\n    }\n    int numDupDigitsAtMostN(int n) {\n        string s=to_string(n);\n        memset(dp,-1,sizeof(dp));\n        int ans=n+1-f(0,s,1,0,1);\n        return ans;\n    }\n};\n```
['Math', 'Dynamic Programming', 'Brainteaser', 'Memoization', 'Bitmask', 'C++']