KMP solution to P0015