### Sukarna_Paul's blog

By Sukarna_Paul, history, 13 months ago,

My Solution with KMP is getting TLE . How can I approach in a faster way? Problem Link

• 0

 » 13 months ago, # |   0 I think it might be due to the character by character match. Here's my kmp code I think it is easy to understand and implement. My_KMPvector prefix_function(string s){ int n=s.size(); vector pi(n); pi[0]=0; for(int i=1;i0 && s[i]!=s[j])j=pi[j-1]; if(s[i]==s[j])j++; pi[i]=j; } return pi; } vector kmp(string s,string t){ int n=s.size(); s=s+"#"+t; vector pf=prefix_function(s); vector occ; for(int i=0;i