Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Print Duplicates in String Array
00:00
5 left

Print Duplicates in String Array

EasyPython

Problem

Write code to print all duplicates in a string array.

Given an array of strings, print each value that appears more than once exactly one time. Preserve the order in which values are first identified as duplicates. Matching is case-sensitive, and repeated occurrences after the first duplicate should not produce additional output.

Input and Output

The function accepts words, a list of strings, and prints each duplicate on its own line. It also returns the printed values as a list for testing.

Constraints

  • 0 <= len(words) <= 10^4
  • Each string contains up to 100 characters
  • Matching is case-sensitive
  • Each duplicate is printed exactly once

Function Signature

def print_duplicates(words):
Interviewer

Your question is Print Duplicates in String Array. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.