implement KMP improved algorithm P[j] != P[k] while getting next