Accounts Merge

Medium

Accounts Merge

Problem Statement

Given a list of employee email addresses and the merging information, find the correct department for each employee. The merging information is represented as a list of operations, where each operation is a tuple or array of three values: the current email, the merged employee's email, and the merged department.

Rules and Constraints

  • The input will contain at most
    100
    employee email addresses.
  • Each employee email will be unique and in the format
    email@example.com
    .
  • The merging operations will not create any conflicts.
  • The input will not contain any invalid email addresses.
  • The algorithm should produce the correct department for each employee.

Input and Output

The input will be in the format of a list of operations, where each operation is a list or tuple of three values: the current email, the merged employee's email, and the merged department.

The output should be a dictionary or hash map where each key is an employee email and the value is the corresponding department.

Time and Space Complexity

The algorithm should aim for a time complexity of O(n) and a space complexity of O(n), where

n
is the number of employee email addresses.

Example

Input: {"input_data":[1,2,3]} Output: [1,2,3]

CompaniesGoogleMetaAmazon
JavaScript

Login to write code

Solve problems, verify your skills, and earn XP.