0Pricing
Competitive Programming Academy · Lesson

KMP Prefix Function

Find a pattern in O(n + m).

The Pattern-Matching Problem

You want to find where a small pattern appears inside a big text. Naive checks are slow, so contests reward a smarter scan. 🔍

Why Naive Search Hurts

Comparing the pattern at every position can cost O(n*m) time. On large inputs that quietly blows your time limit.

All lessons in this course

  1. KMP Prefix Function
  2. Polynomial String Hashing
  3. Z-Function for Pattern Search
  4. Tries for Prefix Lookups
← Back to Competitive Programming Academy