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.
- No Prefix Set
- Discussions
No Prefix Set
No Prefix Set
Sort by
recency
|
177 Discussions
|
Please Login in order to post a comment
very poor description. When it is a bad set, what is specification for the output string? the largest prefix, the shortest prefix, the largest string containg a prefix, I have no clue. Trie solution works to detect if it is a bad set or not.
C++ solution with two maps
m = store each words
pp = store all possible prefix except the word itself
the test case from https://www.hackerrank.com/challenges/one-week-preparation-kit-no-prefix-set/forum/comments/1338749 was super helpful.
In C++, using just such a TrieNode, all 41 Test cases succeeded!
A single
TrieNode* root
, is enough!, Try to insert each character of each word of the given string vector into the tree. During the insert process as soon as you reach a leaf while you have not completely inserted current word, it means that the current word has a prefix. This way might consume more memory but is definitely faster and have lower time complexity in compare with comparing each pair of words in the vector which would be O(n²)These questions are so poorly written. You really need to be more precise about what "being checked" means here.
QUESTION EXPLAINED POORLY and a KEY EXAMPLE SCENARIO is missing. No wonder everyone is saying test cases are broken.
CONSIDER:
4 ee b bb e
I read the problem and thought 'ee' would be the first problem in the list but the test cases are telling me it's bb (after having spent time writing a solution). So... my advice is to add another scenario in the description so that way everyone in this forum doesn't keep trashing this question.