<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:
    def numDupDigitsAtMostN(self, num: int) -> int:
        s = [int(e) for e in str(num)]
        n = len(s)
        dp = [[[0 for _ in range(1<<11)] for _ in range(2)] for _ in range(n+1)]
        # base case
        dp[n][0][0] = dp[n][1][0] = 1

        for i in range(n-1,-1,-1):
            for cselected in range(1<<11):
                for d in range(10):
                    if cselected&1<<d == 0: continue
                    dp[i][0][cselected] += dp[i+1][0][cselected^(1<<d)]
                    if d <= s[i]:
                        dp[i][1][cselected] += dp[i+1][d==s[i]][cselected^(1<<d)]

        ans = 0
        for cselected in range(1<<11):
            ans += dp[0][1][cselected]
            for i in range(1,n):
                if cselected&(1<<0) == 0: continue
                ans += dp[i][0][cselected]
                # if dp[i][0][cselected] != 0:
                #     print(bin(cselected)[2:]+'->'+str(dp[i][0][cselected]),end=' ')
        # print()

        single = ans-dp[0][1][1<<0] 
        for i in range(1,n):
            single -= dp[i][1][1<<0]
        #     print(dp[i][1][1<<0],end=' ')
        # print('single', single)
        return num-single
16800