<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[2][20][2048][2][2];
    int find(bool t,int p, int c, string s, bool can,bool z)
    {
        if(p==s.size())
        {
            return can;
        }
        if(dp[t][p][c][can][z]!=-1)
        {
            return dp[t][p][c][can][z];
        }
        int ans=0;
        for(int i=0; i<10; i++)
        {
            if(z&&i==0)
            {
                ans+=find(false,p+1,0,s,false,true);
            }
            else if(t)
            {
                if(s[p]-'0'>i)
                {
                    ans+=find(false,p+1,c&(1<<i)?c:c+(1<<i),s,can||(c&(1<<i)),false);
                }
                else if(s[p]-'0'==i)
                {
                    ans+=find(true,p+1,c&(1<<i)?c:c+(1<<i),s,can||(c&(1<<i)),false);
                }
            }
            else
            {
                ans+=find(false,p+1,c&(1<<i)?c:c+(1<<i),s,can||(c&(1<<i)),false);
            }
        }
        dp[t][p][c][can][z]=ans;
        return ans;
    }
    int numDupDigitsAtMostN(int n) {
        memset(dp,-1,sizeof(dp));
        string s=to_string(n);
        return find(true,0,0,s,false,true);

    }
};
11200