Javascript version:

var findAllConcatenatedWordsInADict = function(words) { res = [] mp = {} words.forEach(function(word) { mp[word] = 1 }) words.forEach(function(word) { delete mp[word] var c = breakWord(word, mp) if(c>1) { res.push(word) } else if (c== 0) { mp[word] = 1 } }) return res }; var breakWord = function(word, mp) { if(word in mp) return mp[word] for(var i = 1; i < word.length; i++) { var str = word.substring(0, i) if (str in mp && mp[str] > 0) { var c1 = mp[str] var c2 = breakWord(word.substring(i), mp) if(c2 > 0) { mp[word] = c1 + c2 return c1 + c2 } } } mp[word] = 0 return 0 }