substring with concatenation of all words reimpl