CodeMosa

Master LeetCode Patterns

3 Problems

KMP Practice Problems

Prefix function (lps) for exact string matching and related prefix tricks.

Back to Collections

Relevant Patterns

#
Study these pattern guides before tackling the problems. Understanding the core concepts will help you solve them more efficiently.

Practice Problems

#
Show 2 hints
  • Build lps of pattern; walk text with fallbacks using lps.
  • Avoid re‑scanning characters after mismatches.
Show 2 hints
  • KMP on s + # + reverse(s) to find longest palindromic prefix.
  • Prepend reverse of the suffix not covered by the prefix.
Show 2 hints
  • Compute lps over the string and return lps[last].
  • Be careful with full‑string matches (must be proper prefix).

Track Your Progress

Mark problems as complete as you solve them. Come back anytime to continue where you left off.