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

Update with KMP substring search algorithm #229

Closed pandeysubash404 closed 1 month ago

pandeysubash404 commented 1 month ago

Adding more code file required for #219

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

Ritabrata1080 commented 1 month ago

Points to take care :

  1. Try to get a successful check for the rules set.
  2. Squash all the commits.
  3. Consider updating copyright year in the header.

cc : @iluwatar