Facebook | Phone | Returns the pair words (shorter, longer)
Anonymous User
3098

Given a set of words return a pair with prefix and then the full word. The words will only contain english lower case letters and input words are not sorted. Return the pair of words with the small word and then the larger word, for ex - 'be' then 'bee'.

Input : ["abs","app","be","apple","bee","better","bet","absolute"]
Output: [("abs","absolute"),("app","apple"),("be","bee"),("bet","better")]

I couldn't solve the problem on time however, it seems to be a trie problem where all the input words can be put in the trie and scan again. Any pointers or thoughts on how to solve?

Update: updated example with format with few more strings

Comments (20)