Problems > The Cursed Substring > Editorial

The Cursed Substring — Solution & Editorial

Back to the Problem

Digit DP tracking (previous-digit-is-1, already-found-13, tight). It is often easier to count those WITHOUT '13' and subtract, but tracking a 'has13' flag directly works too.

Complexity: O(digits · states)