<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, n: int) -> int:
        numList = list(map(int,str(n)))
        k = len(numList)
        totalNum = 0
        res = 0
        # Less than k digits.
        for j in range(k-1,0,-1):
            res = 9*prod([p for p in range(9, 9-j+1,-1)])
            totalNum += res
        
        # k digits.
        seen = set([])
        for i in range(k):
            leadingDigit = numList[i]
            remainingDigits = k-i-1
            for j in range(0 if i else 1, leadingDigit):
                if j in seen:
                    continue
                res = prod([k for k in range(9-i, 9-i-remainingDigits, -1)])
                totalNum += res
            if leadingDigit in seen:
                break
            seen.add(leadingDigit)
        seen = {}
        for num in numList:
            if num in seen:
                return n-totalNum
            seen[num] = 1
        return n-totalNum - 1
    


16500