100 % runtime 0ms Easy and intuitive
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nSimply find the count o
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSimply find the count of all number that have all digits unique and then eventually subtract from given n . \n\n\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(10)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(10)\n\n# Code\n```\nclass Solution {\npublic:\n    int ans = 0 ; \n\n    bool check(string &temp){\n        if(temp=="")return false;\n        vector<int> v(14);\n\n        for(auto i:temp){ v[i-\'0\']++; }\n        return *max_element(v.begin(),v.end())>1 ;\n    }\n\n    bool check2(string &temp , int index){\n        for(int i=0;i<temp.size() ;i++){\n            if(temp[i]==index)return true;\n        }\n        return false;\n    }\n\n\n    void func(string &temp , string &s , int index){\n        if(check(temp))return;\n        if(index>= s.size()){\n            ans++;\n            return;\n        }\n\n        for(int i=\'0\';i<s[index] ; i++){\n            if(index==0 && i==\'0\')continue;\n            if(check2(temp,i))continue;\n\n            int n = 10-index-1;\n            int k = 1;\n            for(int i=index+1;i<s.size();i++){\n                k = k*n;\n                n--;\n            }\n            // cout<<k<<" ";\n            ans+= k ;\n        }\n\n        temp.push_back(s[index]);\n        func(temp,s,index+1);\n    }\n\n    int numDupDigitsAtMostN(int n) {\n        // n - no. of unique digits \n        string s = to_string(n);\n        int len = s.size(); \n\n        vector<int> dp(13);\n        dp[1]=9;\n        dp[2]=81;\n        dp[3]=dp[2]*8;\n        dp[4]=dp[3]*7;\n        dp[5]=dp[4]*6;\n        dp[6]=dp[5]*5;\n        dp[7]=dp[6]*4;\n        dp[8]=dp[7]*3;\n        dp[9]=dp[8]*2;\n        dp[10]=dp[9]*1;\n\n        for(int i=1;i<=len-1;i++){\n            ans+= dp[i];\n        }\n\n        // cout<<ans<<endl;\n\n        string temp = "";\n        func(temp , s , 0 );\n\n        // cout<<ans<<endl;\n\n        return n-ans; \n\n    }\n};\n```
['C++']