Google | Onsite | Transform-Add Strings
Anonymous User
2655

Wasn't sure what name to give this, the interviewer used "Trans-Add" to describe this process, apologies if this has been posted before. Struggled with this problem in the interview, and was hoping to find an optimal solution.

Problem:
Given two sets of words, e.g., ["ACT", "SET", "FOO"], ["TACK", "TEST", "BAR"], return all words from the second set that can be formed by any combination of letters in a single word plus any single character (any capital letter) from the first set. Duplicate letters may appear, and there is no limit on set sizes.

Example:
["ACT", "SET", "FOO"], ["TACK", "TEST", "BAR"] -> ["TEST", "TACK"]
The letters in the word ACT+K can be found in TACK and the letters in the word SET+T can be found in TEST. There is no combination of letters for any word plus any letter that gives "BAR".

Note: I'm a little unclear on whether or not you can only use some letters from the first set word or if you have to use all of them, but it might be good to see the case where any number of letters is allowed. For what it's worth, the interviewer instructed me to solve the simple case where you simply compare two words (e.g., "ACT" and "TACK"), and then to solve this more general case.

Comments (10)