FastPrepCount Repeated Words
Problems/Count Repeated Words

Count Repeated Words

Datadog logoDatadog● EasyINTERNFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Datadog internship interview report supplied the case-insensitive repeated-word rule, the period/comma punctuation restriction, and the distinct-count interpretation. Bounds and the callable name are authored for practice; the core task matches at about 98%.

Special thanks: A special thank you to the best Rachel~ 🌱

Given a paragraph, count how many distinct words occur at least twice. Matching is case-insensitive, so differently capitalized forms of the same word belong to one group.

The only punctuation marks in the paragraph are periods and commas, and they are used correctly. Punctuation is not part of a word. A word that appears two or more times contributes exactly 1 to the answer, regardless of how many total occurrences it has.

Function

countRepeatedWords(paragraph: String) → int

Examples

Example 1

paragraph = "Sun rises, and sun sets."return = 1

Sun and sun are the same word after case normalization, so sun contributes one.

Example 2

paragraph = "Go, go. GO, stay."return = 1

go appears three times but still contributes only one distinct repeated word.

Example 3

paragraph = "Hello, world."return = 0

Neither word repeats.

Constraints

  • 1 <= paragraph.length <= 200000
  • The paragraph contains English letters, spaces, periods, and commas only.
  • Periods and commas are used correctly and separate from the words they punctuate.
  • The paragraph contains at least one word.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public int countRepeatedWords(String paragraph) {
  // Write your code here.
}
Checking account…