From 5d663e47848ff13ff4c1b7379e6e918616595ba4 Mon Sep 17 00:00:00 2001 From: Milad Khoshdel Date: Sat, 10 Oct 2026 10:21:00 +0330 Subject: [PATCH] fix(strings): handle empty pattern in KMP search --- strings/knuth_morris_pratt.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/strings/knuth_morris_pratt.py b/strings/knuth_morris_pratt.py index 5120779c571e..cff96f52ece0 100644 --- a/strings/knuth_morris_pratt.py +++ b/strings/knuth_morris_pratt.py @@ -22,6 +22,9 @@ def knuth_morris_pratt(text: str, pattern: str) -> int: True """ + if not pattern: + return 0 + # 1) Construct the failure array failure = get_failure_array(pattern)