Your search for interview questions can stop here. Its a Full Stack QA Interview bundle.
This complete QA Automation Interview Kit covers Playwright, Selenium, Python, SQL, API, Cloud, Big Data, and AI Testing with practical questions, clear answers, coding examples, and real-world scenarios.
Don’t waste more time searching for scattered interview questions. Spend your time preparing, practicing, and building confidence with this structured kit.
One kit. Focused preparation. Stronger interview readiness.
Question: How do you find duplicate elements in a list?
Answer:
def find_duplicates(items):
seen = set()
duplicates = set()
for item in items:
if item in seen:
duplicates.add(item)
else:
seen.add(item)
return list(duplicates)
print(find_duplicates([1, 2, 3, 2, 4, 1]))
Explanation:
The seen set stores values already encountered. If a value appears again, it is added to the duplicates set. This approach avoids unnecessary nested loops and provides an efficient solution.