leetcode icon indicating copy to clipboard operation
leetcode copied to clipboard

Bug Report for anagram-groups

Open bluefing opened this issue 11 months ago • 0 comments

Bug Report for https://neetcode.io/problems/anagram-groups

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

The foillowing solution causes an exception in the neetcode editor. It works when run locally with python 3.13.9

class Solution:
# def groupAnagrams(self, strs: List[str]) -> List[List[str]]: # subs = {} # for s in strs: # ss = "".join(sorted(s)) # v = subs.get(ss, []) # v.append(s) # subs[ss] = v # return [ s for s in subs.values() ]

def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
    subs = {}
    for s in strs:
        # bucket by word length
        bucket = len(s)
        if bucket not in subs:
            subs[bucket] = [[s]]

        groups = subs[bucket]

        for i, group in enumerate(groups):
            if s in group:
                continue
            word = group[0]
            match = True 
            for letter in s:
                if letter not in word:
                    match = False
                    break
            
            if match:
                group.append(s)
                groups[i] = group
                break
            else:
                groups.append([s])

    return [ s for s in subs.values() ]

Traceback (most recent call last): File "/box/script.py", line 93, in process_input print_list_no_spaces(output) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^ File "/box/script.py", line 132, in print_list_no_spaces result += """ + item + """ ~~~~~^~~~~~ TypeError: can only concatenate str (not "list") to str

bluefing avatar Dec 03 '25 22:12 bluefing