Find Longest Self-Contained Substring
Grow a candidate substring from each first occurrence, and keep the longest one whose letters never appear outside it.
Grow a candidate substring from each first occurrence, and keep the longest one whose letters never appear outside it.