int hash(String s) {
        int h = 0;
        int prime = 31;
        for (int i = 0; i < s.length(); i++) {
            h += Math.pow(prime, i) * s.charAt(i);
        }
        return h;
    }
There are two solutions for this problem. One is using RabinKarp Algorithm and the second one is using
Java's index of algorithm i.e. searching starting point of needle from haystack and comparing needle.
Time complexity in both algorithms is average O(n+m) and in the worst case O(mn);
src/problems/easy/ImplementstrSt.java