Accounts Merge
Implement solve for Accounts Merge. Return the required output for the provided arguments.
Examples
Input: [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
Output: [["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
Input: [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
Output: [["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
Hints
Model the input as a graph and choose BFS/DFS/topological sort/DSU based on dependency direction.
Track visited/state arrays carefully to avoid revisiting nodes and to handle cycles.
Validate edge cases first (empty graph, disconnected components, or single-node inputs).
Related Problems
Accounts Merge
Implement `solve` for **Accounts Merge**. Return the required output for the provided arguments.