⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 32s17 days 22 hours 19 minutes 32 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 32s17 days 22 hours 19 minutes 32 seconds.

Sign in to watch this lesson
Advanced - Dynamic Programming · 4:28
To count the numbers in [A, B] with a digit property, we compute f(N), the count from 0 to N, by building the numbers digit by digit and answer f(B) - f(A - 1). A tight flag keeps the prefix level with N; once a digit drops below N's digit, the rest of the subtree is free and depends only on the digits left and a small summary (here the digit sum mod 7), so it is memoised once and shared, even across calls. We also handle leading zeros with a started flag and the edge cases A = 0 and 10^18.