<p>Given an integer <code>n</code>, return <em>the number of positive integers in the range </em><code>[1, n]</code><em> that have <strong>at least one</strong> repeated digit</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 20
<strong>Output:</strong> 1
<strong>Explanation:</strong> The only positive number (&lt;= 20) with at least 1 repeated digit is 11.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 100
<strong>Output:</strong> 10
<strong>Explanation:</strong> The positive numbers (&lt;= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> n = 1000
<strong>Output:</strong> 262
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution {
public:
    int dp[15][2][15];
    map<int,int>m;
    int rec(int ind,int hi,int flag,string s){
        if(ind>=s.size())return 1;
        if(dp[ind][hi][flag]!=-1)return dp[ind][hi][flag];
        int ans=0;
        if(hi==0){
            if(flag==0){
                ans+=rec(ind+1,0,0,s)+9*rec(ind+1,0,1,s);
            }
            else{
                ans+=(10-flag)*rec(ind+1,0,flag+1,s);
            }
        }
        else{
            for(int j=0;j<10;j++){
                if(m.find(j)==m.end()){
                    if(j<s[ind]-'0'){
                        if(flag==0 && j==0)ans+=rec(ind+1,0,0,s);
                        else{
                            ans+=rec(ind+1,0,flag+1,s);
                        }
                    }
                    else if(j==s[ind]-'0'){
                        m[j]++;
                        ans+=rec(ind+1,1,flag+1,s);
                    }
                }
            }
        }
        return dp[ind][hi][flag]=ans;
    }
    int numDupDigitsAtMostN(int n) {
        string s="";
        memset(dp,-1,sizeof(dp));
        int temp=n;
        while(n>0){
            s+=to_string(n%10);
            n/=10;
        }
        reverse(s.begin(),s.end());
        int tmp=temp-rec(0,1,0,s)+1;
        return tmp;
    }
};
9000