diff --git a/src/main/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgo.java b/src/main/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgo.java index 1a8f27fac9cb..afa81a5fdc16 100644 --- a/src/main/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgo.java +++ b/src/main/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgo.java @@ -19,6 +19,8 @@ private PatternSearchUsingRabinKarpAlgo() { // I'm using Rabin-Karp algorithm that uses hashing to find pattern strings in a text. public static List search(String text, String pattern) { List result = new ArrayList<>(); + text = text.toLowerCase(); + pattern = pattern.toLowerCase(); int m = pattern.length(); int n = text.length(); int prime = 101; // A prime number to mod hash values diff --git a/src/test/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgoTest.java b/src/test/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgoTest.java index c8d9679687b3..505558079ce2 100644 --- a/src/test/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgoTest.java +++ b/src/test/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgoTest.java @@ -65,7 +65,7 @@ public void testMultipleMatches() { public void testCaseInsensitiveSearch() { String text = "HelloWorld"; String pattern = "helloworld"; - List result = PatternSearchUsingRabinKarpAlgo.search(text.toLowerCase(), pattern.toLowerCase()); + List result = PatternSearchUsingRabinKarpAlgo.search(text, pattern); assertFalse(result.isEmpty(), "Pattern should match regardless of case"); assertEquals("Start: 0, End: 9, Substring: helloworld", result.get(0)); }