Finding substring of a word found in joining a string from another string
Posted
by
2er0
on Stack Overflow
See other posts from Stack Overflow
or by 2er0
Published on 2012-11-20T10:56:29Z
Indexed on
2012/11/20
11:01 UTC
Read the original article
Hit count: 264
string
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
© Stack Overflow or respective owner