|
| 1 | +{ |
| 2 | + "problem_name": "accounts_merge", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "721", |
| 5 | + "problem_title": "Accounts Merge", |
| 6 | + "difficulty": "Medium", |
| 7 | + "topics": "Array, Hash Table, String, Depth-First Search, Breadth-First Search, Union Find, Sorting", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "Given a list of `accounts` where each element `accounts[i]` is a list of strings, where the first element `accounts[i][0]` is a name, and the rest of the elements are **emails** representing emails of the account.\n\nNow, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.\n\nAfter merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails **in sorted order**. The accounts themselves can be returned in **any order**.", |
| 10 | + "readme_examples": [ |
| 11 | + { |
| 12 | + "content": "```\nInput: accounts = [[\"John\",\"[email protected]\",\"[email protected]\"],[\"John\",\"[email protected]\",\"[email protected]\"],[\"Mary\",\"[email protected]\"],[\"John\",\"[email protected]\"]]\nOutput: [[\"John\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Mary\",\"[email protected]\"],[\"John\",\"[email protected]\"]]\n```\n**Explanation:** The first and second John's are the same person as they have the common email \"[email protected]\". The third John and Mary are different people as none of their email addresses are used by other accounts." |
| 13 | + }, |
| 14 | + { |
| 15 | + "content": "```\nInput: accounts = [[\"Gabe\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Kevin\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Ethan\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Hanzo\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Fern\",\"[email protected]\",\"[email protected]\",\"[email protected]\"]]\nOutput: [[\"Ethan\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Gabe\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Hanzo\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Kevin\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Fern\",\"[email protected]\",\"[email protected]\",\"[email protected]\"]]\n```" |
| 16 | + } |
| 17 | + ], |
| 18 | + "readme_constraints": "- `1 <= accounts.length <= 1000`\n- `2 <= accounts[i].length <= 10`\n- `1 <= accounts[i][j].length <= 30`\n- `accounts[i][0]` consists of English letters.\n- `accounts[i][j] (for j > 0)` is a valid email.", |
| 19 | + "readme_additional": "", |
| 20 | + "solution_imports": "", |
| 21 | + "solution_methods": [ |
| 22 | + { |
| 23 | + "name": "accounts_merge", |
| 24 | + "parameters": "accounts: list[list[str]]", |
| 25 | + "return_type": "list[list[str]]", |
| 26 | + "dummy_return": "[]" |
| 27 | + } |
| 28 | + ], |
| 29 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution", |
| 30 | + "test_class_name": "AccountsMerge", |
| 31 | + "test_helper_methods": [ |
| 32 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 33 | + ], |
| 34 | + "test_methods": [ |
| 35 | + { |
| 36 | + "name": "test_accounts_merge", |
| 37 | + "parametrize": "accounts, expected", |
| 38 | + "parametrize_typed": "accounts: list[list[str]], expected: list[list[str]]", |
| 39 | + "test_cases": "[([[\"John\", \"[email protected]\", \"[email protected]\"], [\"John\", \"[email protected]\", \"[email protected]\"], [\"Mary\", \"[email protected]\"], [\"John\", \"[email protected]\"]], [[\"John\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Mary\", \"[email protected]\"], [\"John\", \"[email protected]\"]]), ([[\"Gabe\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Kevin\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Ethan\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Hanzo\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Fern\", \"[email protected]\", \"[email protected]\", \"[email protected]\"]], [[\"Ethan\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Gabe\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Hanzo\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Kevin\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Fern\", \"[email protected]\", \"[email protected]\", \"[email protected]\"]])]", |
| 40 | + "body": "result = self.solution.accounts_merge(accounts)\n# Sort both result and expected for comparison since order doesn't matter\nresult_sorted = [sorted(account) for account in sorted(result)]\nexpected_sorted = [sorted(account) for account in sorted(expected)]\nassert result_sorted == expected_sorted" |
| 41 | + } |
| 42 | + ], |
| 43 | + "playground_imports": "from solution import Solution", |
| 44 | + "playground_test_case": "# Example test case\naccounts = [[\"John\", \"[email protected]\", \"[email protected]\"], [\"John\", \"[email protected]\", \"[email protected]\"], [\"Mary\", \"[email protected]\"], [\"John\", \"[email protected]\"]]\nexpected = [[\"John\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Mary\", \"[email protected]\"], [\"John\", \"[email protected]\"]]", |
| 45 | + "playground_execution": "result = Solution().accounts_merge(accounts)\nresult", |
| 46 | + "playground_assertion": "# Sort for comparison since order doesn't matter\nresult_sorted = [sorted(account) for account in sorted(result)]\nexpected_sorted = [sorted(account) for account in sorted(expected)]\nassert result_sorted == expected_sorted" |
| 47 | +} |
0 commit comments