Remove duplicates, keep the order

lists

Remove duplicates, keep the order

Netflix Python Interview Question

Netflix builds a "Continue watching" row from a member's viewing history, newest first. A title watched several times should only appear once, in the place where it first appears.

Write a function unique_in_order(titles) that returns the list with repeats removed, keeping the first copy of each title and the original order.

Asked of

  • Data Analyst
  • Data Engineer
  • Data Scientist
  • ML Engineer
  • AI Engineer

Example 1

Input

titles = ["Dark", "Ozark", "Dark", "Narcos"]

Output

["Dark", "Ozark", "Narcos"]

Example 2

Input

titles = ["Mindhunter", "Mindhunter"]

Output

["Mindhunter"]

Explanation

In the first example, "Dark" appears twice, but only its first place in the list is kept, so the result is "Dark", "Ozark" and "Narcos".

Submit also runs 3 hidden test cases that check edge cases.