Very Obvious , Intuitive and Easy 13D - DP :)
\n# Code\n\nclass Solution {\npublic:\n    string s;\n\n\n    int dp[11][2][3][3][3][3][3][3][3][3][3][3][2];\n\n    int rec(int index, bool tight, int one, int
\n# Code\n```\nclass Solution {\npublic:\n    string s;\n\n\n    int dp[11][2][3][3][3][3][3][3][3][3][3][3][2];\n\n    int rec(int index, bool tight, int one, int two, int three, int four,\n            int five, int six, int seven, int eight, int nine, int zero,\n            bool lead) {\n\n        if (index == s.size()) {\n            return one == 2 || two == 2 || three == 2 || four == 2 ||\n                   five == 2 || six == 2 || seven == 2 || eight == 2 ||\n                   nine == 2 || zero == 2;\n        }\n\n        int& ans = dp[index][tight][one][two][three][four][five][six][seven]\n                     [eight][nine][zero][lead];\n        if (ans != -1)\n            return ans;\n\n        int lb = 0;\n        int ub = tight ? s[index] - \'0\' : 9;\n        ans = 0;\n\n        for (int i = lb; i <= ub; i++) {\n            int n_one = one, n_two = two, n_three = three, n_four = four,\n                n_five = five, n_six = six, n_seven = seven, n_eight = eight,\n                n_nine = nine, n_zero = zero;\n\n            if (i == 1)\n                n_one++;\n            else if (i == 2)\n                n_two++;\n            else if (i == 3)\n                n_three++;\n            else if (i == 4)\n                n_four++;\n            else if (i == 5)\n                n_five++;\n            else if (i == 6)\n                n_six++;\n            else if (i == 7)\n                n_seven++;\n            else if (i == 8)\n                n_eight++;\n            else if (i == 9)\n                n_nine++;\n            else if (i == 0 && lead)\n                n_zero++;\n\n            ans +=\n                rec(index + 1, tight && (i == ub), min(n_one, 2), min(n_two, 2),\n                    min(n_three, 2), min(n_four, 2), min(n_five, 2),\n                    min(n_six, 2), min(n_seven, 2), min(n_eight, 2),\n                    min(n_nine, 2), min(n_zero, 2), lead || i > 0);\n        }\n\n        return ans;\n    }\n\n    int numDupDigitsAtMostN(int n) {\n        for (int i0 = 0; i0 < 11; i0++)\n            for (int i1 = 0; i1 < 2; i1++)\n                for (int i2 = 0; i2 < 3; i2++)\n                    for (int i3 = 0; i3 < 3; i3++)\n                        for (int i4 = 0; i4 < 3; i4++)\n                            for (int i5 = 0; i5 < 3; i5++)\n                                for (int i6 = 0; i6 < 3; i6++)\n                                    for (int i7 = 0; i7 < 3; i7++)\n                                        for (int i8 = 0; i8 < 3; i8++)\n                                            for (int i9 = 0; i9 < 3; i9++)\n                                                for (int i10 = 0; i10 < 3;\n                                                     i10++)\n                                                    for (int i11 = 0; i11 < 3;\n                                                         i11++)\n                                                        for (int i12 = 0;\n                                                             i12 < 2; i12++)\n                                                            dp[i0][i1][i2][i3]\n                                                              [i4][i5][i6][i7]\n                                                              [i8][i9][i10][i11]\n                                                              [i12] = -1;\n\n        s = to_string(n);\n        return rec(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);\n    }\n};\n```
['C++']