<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>

int dp[11][1024][2][2];
class Solution 
{
private:
    int solve(int i, int mask, int high, int zero, int &n, string &num)
    {
        if(i == n)
            return 1;
        if(dp[i][mask][high][zero] != -1)
            return dp[i][mask][high][zero];
        int higher_limit = 9;
        if(high)
            higher_limit = num[i] - '0';
        int ans = 0;
        for(int digit = 0; digit <= higher_limit; digit++)
        {
            if(mask & (1 << digit))
                continue;
            int new_high = high;
            if(digit < higher_limit)
                new_high = 0;
            int new_mask = mask, new_zero = zero;
            if(zero)
            {
                if(digit)
                    new_mask = mask | (1 << digit), new_zero = 0;
            }
            else
                new_mask = mask | (1 << digit);
            ans += solve(i + 1, new_mask, new_high, new_zero, n, num);
        }
        return dp[i][mask][high][zero] = ans;
    }
public:
    int numDupDigitsAtMostN(int n) 
    {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);

        string num = to_string(n);
        int N = num.size();
        memset(dp, -1, sizeof(dp));
        return n + 1 - solve(0, 0, 1, 1, N, num);
    }
};
8000