Count numbers with all distinct digits. Use a bitmask to track used digits. Start: mask = 0, tight = true, started = false. Position : try (leading zero, don't add to mask), 1 (mask |= 2).
If we chose 1 (mask = 0b10, tight = true): position can be , , (not 1, it's used). If we choose (> limit's 3), invalid. Continue to position . Count paths where each digit appears at most once. Bitmask tracks usage in per transition.