I was learning rabin karp algorithm and solving a basic problem of finding indices of pattern in a string with the help of string hashing technique. But the code is just not printing out anything.
I used this algorithm yesterday to solve a problem and got AC but now I'm unable to find where's the issue.
here's my code-
#include using namespace std; typedef long long ll; ll mod = 1000000007; #define max 100005 int p = 31; ll hashfunction[max], power[max]; void precompute(string text, int n){ power[0]=1; hashfunction[0] = text[0]-'a'+1; ll pow = p; for(int i=1; i
ll getHash(int l, int r){ if(l==0) return hashfunction[r]; else return (mod + hashfunction[r] — (hashfunction[l-1]*power[r-l+1])%mod)%mod; } ll computeHashofstring(string pattern){ ll hash_value = 0; for(int i=0; i
vector solve(string text, string pattern){ vector v; precompute(text, text.length()); ll hashofpattern = computeHashofstring(pattern); int left=0, right=pattern.length()-1; while (right> text >> pattern; vector v = solve(text, pattern); for(int i=0; i<< v[i] << '\n'; return 0; }