Skip to main content
๐Ÿ“œ 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 Code
Digit TrioDigit-sum multiple-of-3 counting, contains-7 counting, and exact-K digit-sum counts under a heavy query load.
3 challenges ยท ยท ~110 min