Python (Simple Digit DP)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def numDupDigitsAtMostN(self, n):\n        ans = [int(i) for i in str(n)]\n        m = len(ans)\n\n        @lru_cache(None)\n        def function(pos,tight,mask):\n            if pos == m:\n                return 1 \n\n            total = 0 \n\n            upperlimit = ans[pos] if tight else 9 \n\n            for d in range(upperlimit+1):\n                if mask&(1<<d) == 0:\n                    new_tight = tight and d == upperlimit \n                    new_mask = mask if mask == 0 and d == 0 else mask|(1<<d)\n                    total += function(pos+1,new_tight,new_mask)\n\n            return total \n\n        return n-(function(0,True,0)-1)\n```
['Python3']