Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

First Repeated Word in Paragraph

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is First Repeated Word in Paragraph. Start with the requirements on the right.

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.

Problem

Given a string text, return the first word that repeats when scanning from left to right. Comparison should be case-insensitive, and punctuation should be ignored. If no word repeats, return an empty string.

Constraints

  • 1 <= len(text) <= 10^5
  • text contains letters, digits, spaces, and punctuation
  • Word matching is case-insensitive
  • Ignore leading, trailing, and repeated punctuation around words

Function Signature

def first_repeated_word(text):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output