Thought I would give some tips here from an interviewing standpoint. Although your solution is “technically” correct Jean, it would unfortunately reflect very poorly and be an automatic fail in any technical interview.

From a technical interviewing standpoint, basic algorithms questions like this one serve two main purposes:

1) Does the interviewee have the ability to solve the problem without relying on built-in language specific functions and/or libraries?

2) Does the interviewee display a basic knowledgebase in Data Structures & Algorithms, computational complexity and running-times (and hence scalability), and is capable of choosing the “best” solution to the problem that is both simple and computationally efficient?

Your solution Jean is a fail because:

1) You relied on a built-in sorting library

2) Sorting the two lists and then comparing them is computationally inefficient. The asymptotic complexity of your solution is O(nln(n)). Chris’s solution with the use of hash tables (python dictionaries) has complexity O(n) and is absolutely the “correct” approach for this problem from a technical interviewing standpoint.

Most companies ask these types of questions in first-round screening interviews purposely to weed out people early. Even though your solution technically answers the question Jean, a naive solution like yours would be an automatic fail and you wouldn't move to the next round. As frustrating as that is, that’s how the technical interviewing game works.

Principal Data/ML Scientist @ The Cambridge Group | Harvard trained Statistician and Machine Learning Scientist | Expert in Statistical ML & Causal Inference

Principal Data/ML Scientist @ The Cambridge Group | Harvard trained Statistician and Machine Learning Scientist | Expert in Statistical ML & Causal Inference