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.
This problem is very frustrating and unclear.
If I understood it correctly, it asks the following:
For each word w, check if any other word in the array is a prefix of w.
If yes, print 'BAD SET' followed by w on the next line and stop the execution.
If no prefix was found for any of the words in the list, print 'GOOD SET'.
However, there's one example in which my code fails that says the expected
result is 'BAD SET d', even though there's no other 'd' in the words list,
which would be the only way to make the expected result correct.
Only the word itself can be its prefix if its length is equal to one.
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 →
This problem is very frustrating and unclear. If I understood it correctly, it asks the following:
For each word w, check if any other word in the array is a prefix of w. If yes, print 'BAD SET' followed by w on the next line and stop the execution. If no prefix was found for any of the words in the list, print 'GOOD SET'.
However, there's one example in which my code fails that says the expected result is 'BAD SET d', even though there's no other 'd' in the words list, which would be the only way to make the expected result correct. Only the word itself can be its prefix if its length is equal to one.