Skip to content

Bug Report for accounts-merge #4292

Open
@paplant

Description

@paplant

Bug Report for https://neetcode.io/problems/accounts-merge

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

Image

The problem description says the accounts can be returned in any order, but the judge does care about the order of the accounts. This was my code:

class User:
    def __init__(self, name, emails):
        self.name = name
        self.emails = set(emails)

class Solution:
    def accountsMerge(self, accounts: List[List[str]]) -> List[List[str]]:
        email_mapping = {}
        for account in accounts:
            user_account = User(account[0], account[1:])
            other_accounts = set()
            for email in user_account.emails:
                if email in email_mapping:
                    other_accounts.add(email_mapping[email])
            for other_account in other_accounts:
                user_account.emails |= other_account.emails
            for email in user_account.emails:
                email_mapping[email] = user_account
        users = set(user for user in email_mapping.values())
        return [[user.name] + sorted(user.emails) for user in users]

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