golang dp
\ncount(0, dn...d1) = count(0, 9...9) + count(10...0, dn...d1)\ncount(10...0, dn...d1) = count(10...0, dn0...0-1) + count(dn0...0, dn...d1)\n\ndefine dp(s, n), 
\ncount(0, dn...d1) = count(0, 9...9) + count(10...0, dn...d1)\ncount(10...0, dn...d1) = count(10...0, dn0...0-1) + count(dn0...0, dn...d1)\n\ndefine dp(s, n), the count for numbers who has n-digits not determined yet and s is its 0-9 indicator for its known digits. (do not care whether its known digits are all 0s)\ndp(s, n) = sum(s&(1<<i)? 10...0: dp(s|1<<i, n-1) for i in 0...9 )\n\nhence:\ncount(0, 9...9) = sum(countd(n) for n in {1..dn}) and countd(n) = sum(dfs(1<<i, n-1) for i in {1..9})\ncount(dn0...0, dn...d1) = sum(count(dni0...0, dn(i+1)0...0-1)  for i in {0...d(n-1)-1})\nkeep track of the 0-9 mask for the processed digits, and if 0-9 mask already 1, then count all the possibles , otherwise solve sub problem.\n\nMaybe this is way too unnecessarily complex...... sadly this is how my brain wired....\n```\nvar dp map[int]int\nvar cs = []int{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}\n/* s is a 10-bit map indicating whether 0-9 digits already exist\ndp[s][n] yield a count for numbers which have at least  n digits number, and some prefix map s\n*/\nfunc dfs(s, n int) int {\n    if n<=0 { return 0; }\n    k := (s<<4)|n;\n    if v, ok := dp[k]; ok {\n        return v\n    }\n    c := 0\n    var i uint\n    for i=0; i<10; i++ {\n        if (s&(1<<i)) != 0 {\n            c += cs[n-1]\n        } else {\n            c += dfs(s|(1<<i), n-1)\n        }\n    }\n    dp[k] = c\n    return c\n}\n\n/* count n digit numbers, between 10...0 to 99...9 */\nfunc count(n int) int {\n    if n<=1 { return 0 }\n    c := 0\n    var i uint\n    for i=1; i<10; i++ {\n        c += dfs(1<<i, n-1)\n    }\n    return c\n}\n\nfunc numDupDigitsAtMostN(N int) int {\n    if dp==nil { dp = make(map[int]int) }\n    rem := make([]int, 10)\n    for i:=0; i<10; i++ { rem[i] = N % cs[i] }\n    d, ds := 0, make([]uint, 16)\n    for {\n        ds[d] = uint(N % 10)\n        d += 1\n        N /= 10\n        if N==0 { break }\n    }\n    c, s := 0, 0\n    /* accumulate counts from 0 to 9...9, where 9...9 < N */\n    for i:=1; i<d; i++ { c += count(i) }\n    /* from higher digit down, accumulate d(i+1)0..0 to d(i+1)d(i)0..0-1 */\n    for i:=d-1; i>=0; i-- {\n        var j uint\n        if i==d-1 {j=1}\n        for ; j<ds[i]; j++ {\n            if ((s&(1<<j)) != 0) {\n                c += cs[i]\n            } else {\n                c += dfs(s|(1<<j), i);\n            }\n        }\n        if (s&(1<<ds[i])) != 0 {\n            /* all the remaining numbers should be counted */\n            c += (rem[i]+1)\n            break\n        }\n        s |= (1<<ds[i])\n    }\n    return c\n}\n```
[]