Python Solution Using Combinatorics and beats 94% of submissions
Code\n\nclass Solution:\n    def numDupDigitsAtMostN(self, n: int) -> int:\n        strn = str(n)\n        length = len(strn)\n        low = 0\n        for i in
# Code\n```\nclass Solution:\n    def numDupDigitsAtMostN(self, n: int) -> int:\n        strn = str(n)\n        length = len(strn)\n        low = 0\n        for i in range(1,length):\n            low+=(9*(math.factorial(9)//math.factorial(9-i+1)))\n        topval = int(strn[0])\n        diff = topval-1\n        mid=diff*(math.factorial(9)//math.factorial(9-length+1))\n        left = 9\n        pos = 1\n        seen = set([topval])\n        def trav(pos,left,seen):\n            nonlocal strn, length\n            if pos == length:\n                return 1\n            current = int(strn[pos])\n            sub = 0\n            for item in seen:\n                if item < current:\n                    sub+=1\n            add = (current-sub)*(math.factorial(left-1)//math.factorial(10-length))\n            if current in seen:\n                return add\n            else:\n                seen.add(current)\n                add+=trav(pos+1,left-1,seen)\n            return add\n        top=trav(pos,left,seen)\n        return n-(low+mid+top)\n```
['Python3']