~/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.
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
- Basics: Count numbers with a given digit sum basics py · c++ · java easy
- Raffle tickets short on ink py · c++ · java easy
- Count the digit 1 py · c++ · java medium
- Numbers with no equal neighbouring digits py · c++ · java medium