Given a string and a list of words of the same length, find all start indices in the string of concatenations of each word.
For example, for string
"barfoomanthefoobar" and words
"bar"] the corresponding indices are
Input. The input consists of two lines. The first line is the string where you will search for concatenations of words. The second line is the list of words. Words are separated by a single space.
Output consists of a single line. The line consists of all the indices separated by a single space. Order of the indices does not matter.
Here is a Ruby implementation.
Want to read more?
I regularly write solutions to programming problems that you may or may not find in technical job interviews. I also love to explain those solutions and answer questions. If you would like to get the latest problem + solution, subscribe to the newsletter or subscribe via RSS. You can also follow me on Twitter, GitHub, and LinkedIn.