100% Faster Solution using Math and Recursion TC : O(1)  || C++ Explained
Please upvote if you like my solution .\n\nclass Solution {\npublic:\n    // to return factorial starting at st and multiplying till t no of times\n    int fac(
**Please upvote if you like my solution .**\n```\nclass Solution {\npublic:\n    // to return factorial starting at st and multiplying till t no of times\n    int fac(int st,int t){\n        int ans = 1;\n        while(t){\n            ans *= st;\n            st--;\n            t--;\n        }\n        return ans;\n    }\n    // mask will create mask over digits fixed\n    vector<bool> mask;\n    // we are counting numbers with 0 duplicate digits\n    int solve(vector<int> &dig, int ind, int st){\n        if(ind == dig.size()) return 1;\n        int ans = 0;\n        if(ind == 0){\n            // 0 cannot be used\n            for(int i=1;i<dig[ind];i++){\n                if(i < dig[ind]){\n                    ans += fac(st,dig.size()-1);\n                }\n            }\n            // here we are fixing digit equal to dig[ind] and masking it to use in future\n            mask[dig[ind]] = 1;\n            // now calling solve for next index\n            ans += solve(dig,ind + 1, st);\n            return ans;\n        }\n        // if we are not at first index means we can use 0 now\n        for(int i=0;i<dig[ind];i++){\n            if(mask[i]) continue; // see if we have used this digit before than we cannot indclude its contribution\n            if(i < dig[ind]){\n                ans += fac(st-1,dig.size()-ind-1);\n            }\n        }\n        // if we have used dig[ind] before than return ans no need to solve for next index \n        if(mask[dig[ind]]) return ans;\n        mask[dig[ind]] = 1;\n        ans += solve(dig,ind + 1,st-1);\n        return ans;\n    }\n    \n    int numDupDigitsAtMostN(int n) {\n        // here we can use 10 digits including 0 but must not start with zero\n        if(n<=10) return 0;\n        int nc = n;\n        vector<int> dig;\n        while(nc){\n            dig.push_back(nc%10);\n            nc /= 10;\n        }\n        reverse(dig.begin(), dig.end());\n        // now we have digits\n        mask.resize(10,0);\n        // till number of n digits\n        vector<int> v(10,0); // this contains numbers that have unique digits in ith digit number\n        long int a = 9;\n        for(int i=1;i<10;i++){\n            v[i] = a;\n            a = a*(10-i);\n        }\n        // Now till we try n digits number \n        int ans = 0;\n        for(int i=1;i<dig.size();i++){\n            ans += v[i];\n        }\n        // Now for dig.size digit number we can\n        ans += solve(dig,0,9);\n        return n-ans;\n    }\n};\n```\n![image](https://assets.leetcode.com/users/images/036658bb-d5e8-4718-aea0-26590569bf1a_1667148845.2003994.png)\n
['Math', 'Recursion', 'C']