C++ Solution || Digit DP Solution
cpp\nclass Solution {\npublic:\n    int dp[10][1<<10][2][2];\n    int solve(string &nums,int i=0,int mask=0,bool rep=0,int tight=1){\n        if(i>=nums.size())
```cpp\nclass Solution {\npublic:\n    int dp[10][1<<10][2][2];\n    int solve(string &nums,int i=0,int mask=0,bool rep=0,int tight=1){\n        if(i>=nums.size())\n            return rep and mask!=0;\n        if(dp[i][mask][rep][tight]!=-1)\n            return dp[i][mask][rep][tight];\n        int ub=tight?(nums[i]-\'0\'):9;\n        int ans=0;\n        for(int j=0;j<=ub;j++){\n            if(mask==0 and j==0 )\n                ans+=solve(nums,i+1,mask,rep,tight&(j==ub));\n            else if(mask&(1<<j))\n                ans+=solve(nums,i+1,mask,true,tight&(j==ub));\n            else\n                ans+=solve(nums,i+1,mask|(1<<j),rep,tight&(j==ub));\n        }\n        return dp[i][mask][rep][tight]=ans;\n    }\n    int numDupDigitsAtMostN(int n) {\n        string nums=to_string(n);\n        memset(dp,-1,sizeof(dp));\n        return solve(nums);\n    }\n};\n```
[]