Skip to content
StackDecode
Dynamic programmingExplained

Digit DP

Count numbers with a property by building them digit by digit.

Time

O(digits · states)

Extra space

O(digits · states)

Use it for

Counting numbers up to N with constraints.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.