Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Contest 4-B: Motif Counter

โญ beginnerโณ 40 min read๐Ÿ“ Lesson 200 of 281

Mock contest 4, problem B: overlapping occurrence counting with KMP. Target: solved within 40 minutes.

Contest 4-B โ€” Motif Counter. KMP matching with the standard j = fail[j] after a hit keeps overlapping occurrences. Graded near-miss: the non-overlapping find loop.

Contest 4-B. The wrong version's loop advances by the pattern length after each hit โ€” "aa" in "aaaaa" reports 2 instead of 4.