Distinct Echo Substrings - Problem
Given a string text, return the number of distinct non-empty substrings that can be written as the concatenation of some string with itself.
In other words, count all substrings that can be written as a + a where a is some non-empty string.
For example, if text = "abcabc", then "abcabc" can be written as "abc" + "abc", so it counts as an echo substring.
Input & Output
Example 1 — Basic Case
$
Input:
text = "abab"
›
Output:
1
💡 Note:
Only "abab" is an echo substring ("ab" + "ab"). The substring "ab" by itself is not an echo since "a" ≠ "b".
Example 2 — Longer String
$
Input:
text = "aabaaba"
›
Output:
2
💡 Note:
Echo substrings: "aa" appears at multiple positions but counts once, and "aabaab" ("aab" + "aab").
Example 3 — No Echoes
$
Input:
text = "a"
›
Output:
0
💡 Note:
Single character cannot form an echo substring (need at least length 2)
Constraints
- 1 ≤ text.length ≤ 2000
- text consists of lowercase English letters only
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code