Rabin-Karp Algorithm

How can e print all occurences of the pattern in the string?What change is needed in the code?I tried removing the return statement inside the first if block so that a new hash value is evaluated everytime after the first if block,but it doesnt work like that

abbabcabbcabba
abba

I want to make the code work for the above inputs

hi @aryamaan1011 run the program for the input you have mentioned, it is giving all the occurrences of the pattern.

I have tried running it just gives 0 as output…and how will it print all instances we are retruning 0 inside the first if block so it will terminate after the first occurence right?

This is the code

And the code is sent u earlier it does not give any output at all…plz check it.

the code is same as the first code…

@aryamaan1011 i tried the first code on CB IDE its working fine for me.
Remove this part when you are working in the online IDE
image

see the output now, its working fine

I dont know for some reason it wasnt showing the output earlier even though i had removed the input output part of the code…but now its showing correct answer…Thank You!!

1 Like

@aryamaan1011 dont forget to mark your doubt as resolved!