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
|
222 Discussions
|
Please Login in order to post a comment
Tried using
.sort()
which could have been an effectiveO(n)
solution as you only have to compare neighbouring words. Unfortunately this violates the "tested first" condition due to the reordering of words:The test cases are bad. They are bad because author is making an assumption on which data structure the developer is going to use. If you try to brute force the problem then you might be left scratching your head as to why it is not working. But if you use a Trie then the test cases make sense.
For example on test case 1:
If you use brute force you will check first if aab is a prefix of any other words in the list. This means that you will test aabghgh first and that is what you will print.
If you use a Trie tree, then you will first start building the tree with aab, next you will modify the tree with aac, then you will begin to modify the tree with aacghgh. At this point you will find that aacghgh does have a prefix, and it will get printed, thus passing the test case.
Test cases should be written in a way that are agnostic of the algorithm that the developer uses to solve it. There are always so many ways to solve the same problem. If the test cases are not agnostic then it should be clear to the developer what algorithm should be used up front.
That's the end of the 1 week prep kit, it was something ig, what do I get
Horrible question descrtiption...
For some test cases it seems to want the first word that is a prefix (even if it comes after a word that contains a prefix), and for others it wants the first word that contains a prefix. Anyone else experience this?