We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Same thing happened to me. My solution was only checking if the current word contained the ending of a previous word in the list (meaning the current word has a previous word as a prefix).
The solution should also check the reverse (i.e., is the current word the prefix of a previous word?). I did this by using a Trie (which you probably already did) and, after inserting the full word into the Trie (i.e., after reaching the end of the word), checking if the ending node has any children. If yes, the current word is the prefix of a previous word.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
No Prefix Set
You are viewing a single comment's thread. Return to all comments →
Same thing happened to me. My solution was only checking if the current word contained the ending of a previous word in the list (meaning the current word has a previous word as a prefix).
The solution should also check the reverse (i.e., is the current word the prefix of a previous word?). I did this by using a Trie (which you probably already did) and, after inserting the full word into the Trie (i.e., after reaching the end of the word), checking if the ending node has any children. If yes, the current word is the prefix of a previous word.