Made pattern finding linear time