Skip to main content
๐Ÿ“œ WAYPOINT LESSON

The Tight Walk

โญโญโญ advancedโณ 30 min read๐Ÿ“ Lesson 157 of 281

Fix the high digits to N's prefix, branch below the boundary digit, and the suffix becomes a free combinatorial count.

Walking the boundary

To count x in [1, N] with property P, walk N's digits left to right. At position i, every x whose first i digits match N's prefix is "tight"; choosing any digit below N's digit there breaks tightness forever, and the remaining suffix is FREE: any combination of digits is allowed, so the count is a precomputed table, not a search.

The tight chain dies the moment you pick d < lim โ€” that one-way door is the whole structure of digit DP.