iluwatar / 30-seconds-of-java

Collection of reusable tested Java 17 compatible code snippets that you can understand in 30 seconds or less.
https://java-design-patterns.com/snippets.html
MIT License
1.04k stars 409 forks source link

Create KMP substring search algorithm to String Operations #218

Closed pandeysubash404 closed 1 month ago

pandeysubash404 commented 1 month ago

Implements the Knuth-Morris-Pratt (KMP) algorithm to efficiently find the first occurrence of a pattern in a given text. Uses the Longest Prefix Suffix (LPS) array to minimize unnecessary comparisons, resulting in a time complexity of O(n + m).

kmpSearch("abxabcabcaby", "abcaby") returns 6 since the pattern "abcaby" starts at index 6.

sonarcloud[bot] commented 1 month ago

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud