Challenge: Find Duplicates in a List With No Repetition
Write a function to find the duplicates in a list with no repetition, in the most efficient way.
We'll cover the following
Problem statement
Given a list of integers, find all the duplicates that exist in that list.
Input
A list of duplicate integers
Note: All the integers are less than the size of the list.
Output
A list with the duplicates if they exist, and an empty list if they don’t
Sample input
lst = [1, 3, 1, 3, 5, 1, 4, 7, 7]
Sample output
result = [1, 3, 7]
Coding exercise
First, take a close look at this problem and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided in the solution section. Good luck!
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.