How many integers from to have all distinct digits? You can't loop through them. There are too many. But you can count them by building numbers digit by digit. Digit DP (dynamic programming) solves counting problems over huge ranges of numbers.
Instead of checking each number, you construct valid numbers one digit at a time, tracking constraints as you go. I'll show you how to count numbers satisfying digit-based properties. By the end, you'll handle problems that would otherwise be impossible to brute force.