KMP find logic