Find Repeated Substrings Ignoring Case
Problem statement
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-Zora-z.