Feature #8: Merge Recommendations

Implementing the "Merge Recommendations" feature for our "Amazon" project.

Description

Amazon has acquired a new company that already has a database of user-profiles and their corresponding product recommendation data. Now, Amazon wants to check if any of their current users have an account on the acquired website, so they can use the recommendation data. To accomplish this, Amazon has decided to merge the users’ accounts. We will be using the name of the user and the emails associated with their account to determine if multiple accounts belong to the same person. A person may have provided primary, secondary, tertiary emails, etc when setting up an account on either of the websites

We will be given a 2D array of accounts. Each element, accounts[i], is an array of strings, such that accounts[i][0] is a name while the remaining elements are emails associated with that account. We have to determine if two accounts belong to the same person by checking if both accounts have at least one email in common. Remember that if two accounts have the same name, they might belong to different people, as people can have the same name. However, all accounts that belong to one person will have the same name. Moreover, there can be more than two accounts made by one person.

The output should be the merged accounts in which the first element of each account is the name and the rest of the elements are emails in sorted order.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.