FastPrepFind Repeated Substrings Ignoring Case
Problems/Find Repeated Substrings Ignoring Case

Find Repeated Substrings Ignoring Case

Datadog logoDatadog● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The author vaguely recalls a string parser that found repeated substrings, with attention to case. This practice takes substring literally and defines case normalization, overlapping occurrences, all-length distinct output, sorting, alphabet and bounds. It does not claim the original regex task or examples were recovered. The core task matches the recollection at about 70%.

Find every distinct nonempty substring that occurs at least twice in text. A substring is a contiguous sequence of characters.

Ignore ASCII letter case by converting the input to lowercase before comparing substrings. Two occurrences must start at different positions, but they may overlap. Count substrings of every positive length, including single letters.

Return each repeated substring once, in lowercase lexicographic order. A shorter string comes first when it is a prefix of another. Return an empty array when nothing repeats.

Function

repeatedSubstrings(text: String) → String[]

Examples

Example 1

text = "banana"return = ["a","an","ana","n","na"]

a starts at indices 1, 3 and 5. an and ana each start at 1 and 3. n and na each start at 2 and 4. These are the five repeated substrings, listed in lexicographic order.

Example 2

text = "aAaA"return = ["a","aa","aaa"]

The normalized string is aaaa. Substrings of lengths 1, 2 and 3 each have at least two starting positions. The two length-3 occurrences start at 0 and 1 and overlap. The full length-4 string occurs once.

Example 3

text = "AbCd"return = []

The normalized string is abcd. Every letter occurs once, so no longer substring can occur twice either.

Constraints

  • 0 <= text.length <= 40
  • Every character is an ASCII letter: A-Z or a-z.

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 String[] repeatedSubstrings(String text) {
    // Write your code here.
}
Checking account…