Finding substring of a word found in joining a string from another string
- by 2er0
Given a list of words, L, that are all the same length, and a string, S, find the starting position of the substring of S that is a concatenation of each word in L exactly once and without any intervening characters. This substring will occur exactly once in S.
Example:
L: "fooo", "barr", "wing", "ding", "wing"
S: "lingmindraboofooowingdingbarrwingmonkeypoundcake"
Word found in joining L and also found in S: "fooowingdingbarrwing"
Answer: 13
L: "mon", "key"
S: "monkey
Word found in joining L and also found in S: "monkey
Answer: 0
L: "a", "b", "c", "d", "e"
S: "abcdfecdba"
Word found in joining L and also found in S: "ecdba
Answer: 5