<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 numDupDigitsAtMostN(int n)
    {
        int dp[12][2][1<<(11)];
        memset(dp,-1,sizeof(dp)); 
        string s = to_string(n);
        int len = s.size();
        function<int(int,int,int)> recur = [&](int index,int tight,int mask) ->int
        {
            if(index == len){
                return 1;
            }
            if(dp[index][tight][mask]!=-1)return dp[index][tight][mask];
            int limit = tight ? s[index]-'0'  : 9 ;
            int ans = 0;
            for(int i=0;i<=limit;i++)
            {
                int  nmask = mask  , newtight = tight && (i==limit);
                if(  (mask & (1<<i) ))
                {
                   continue;
                }
                // if mask is 0 then it signifies digits 1 to 9 have not appeared
                // then if current digit is 0 this doesn't count as valid number
                if(mask==0 and i==0)
                {
                 nmask = mask ;
                }
                else
                {
                    nmask = mask  | (1<<i);
                }
                ans = ans + recur(index+1,newtight,nmask);
            }
            return dp[index][tight][mask] =  ans;
        };

        return  n+1-recur(0,1,0) ;
    }   
};
8900