๐ WAYPOINT LESSON
Aggregating More Than Counts
โญโญโญ advancedโณ 30 min read๐ Lesson 159 of 281
The same walk collects sums, maxima, or per-state pairs (sum, count) โ the DP state carries whatever the answer needs.
Beyond counting
Swap the free table for a (sum, count) pair and the tight walk returns the total digit sum of a range, the count of numbers containing a digit, or any per-position aggregation. Digit sum exactly K adds a budget dimension: the state is (position, remaining budget, tight), and each digit consumes budget. Leading zeros are the classic trap โ decide whether they count and compensate once.
โก Now practice
Ready to CodeDigit TrioDigit-sum multiple-of-3 counting, contains-7 counting, and exact-K digit-sum counts under a heavy query load.
3 challenges ยท ยท ~110 min