~/problems

Problems

Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.

Advanced DP

Digit DP

Count numbers <= N with a property: position, tight flag, state.

Notes

Recognise it when: you're counting numbers in [0, N] whose digits satisfy something (a digit sum, a count of 1s, no repeats).

Recurse over digit positions with a tight flag (are we still equal to N's prefix?) and whatever state you need, memoized on (pos, tight, state). For a range [L, R], compute f(R) - f(L - 1).

Gotchas: leading zeros, when they affect the state.

4 problems

Advanced & competitive

Advanced DP Bitmask and digit DP.

Digit DP

esc