Skip to content

Bug Report for anagram-groups #5800

@calebkenney15

Description

@calebkenney15

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.

Image Image Image

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions