Bug Report for https://neetcode.io/problems/anagram-groups
My code passes 2/2 test cases when I click run. However, it fails submission even though the input is the same. The output contains words that aren't provided in the original input.
Code:
class Solution:
words = []
grouped_anagrams = []
matches = []
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
if len(strs) < 1 or len(strs) > 1000:
print("Error: The length of the provided array is out of range.")
return None
for word in strs:
if len(word) > 100:
print("Invalid Word:", word)
return None
else:
self.words.append(word.lower())
for i in range(0, len(self.words)):
self.checkMatches(self.words[i], self.words)
return self.grouped_anagrams
def checkMatches(self, current_word : str, wordlist : List[str]):
if current_word in self.matches:
return
else:
self.matches.append(current_word)
anagram_group = [current_word]
for word in wordlist:
appendWord = True
if word in self.matches:
continue
else:
for letter in current_word:
if letter not in word:
appendWord = False
if appendWord == True:
anagram_group.append(word)
self.matches.append(word)
appendWord = False
self.grouped_anagrams.append(anagram_group)
Bug Report for https://neetcode.io/problems/anagram-groups
My code passes 2/2 test cases when I click run. However, it fails submission even though the input is the same. The output contains words that aren't provided in the original input.
Code:
class Solution: