Saturday 19 May 2012

C-Programming Challenge Interview Question


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"
                 fooowingdingbarrwing
Answer: 13

L: "mon", "key"
S: "monkey
    monkey
Answer: 0

L: "a", "b", "c", "d", "e"
S: "abcdfecdba"

0 comments:

Post a Comment