add a KMP based solution