- Notifications
You must be signed in to change notification settings - Fork2.4k
Open
Description
Bug Report forhttps://neetcode.io/problems/accounts-merge
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
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
Labels
No labels