Dynamic Programming21 sections · 916 units
Open in Course

Intro

What you'll learn

How many integers from 11 to 101810^{18} 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.