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.
I managed to have a solution passing tests other than dictionary tree.
Sort the words. For each word check with words greater than it and break when not a prefix. Among the pair, the one with greater index in the unsorted original array is the one triggering the "BAD SET". However we need to iterate to the end and keep the first.
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 →
I managed to have a solution passing tests other than dictionary tree. Sort the words. For each word check with words greater than it and break when not a prefix. Among the pair, the one with greater index in the unsorted original array is the one triggering the "BAD SET". However we need to iterate to the end and keep the first.