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.
for i, word in enumerate(words):
if word in word_dict:
word_dict[word].append(i)
else:
word_dict[word] = [i]
bad_ind = float('inf')
for i, word in enumerate(words):
if i == bad_ind:
break
# Check substrings
for j in range(len(word)-1):
if word[0:j+1] in word_dict:
bad_ind = min( bad_ind, max(i, word_dict[word[0:j+1]][0]) )
# Check if full string repeats
if len(word_dict[word]) > 1:
bad_ind = min(bad_ind, word_dict[word][1])
if bad_ind == float('inf'):
print("GOOD SET")
else:
print("BAD SET")
print(words[bad_ind])
return
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'd love to hear some opinions on my solution.
def noPrefix(words): word_dict = dict()