#C10862. Longest Distinct Substring
Longest Distinct Substring
Longest Distinct Substring
Given an input string s, find the longest substring that contains only distinct characters. In other words, identify a contiguous segment of the string where no character repeats and the segment's length is maximized. If there exist multiple substrings with the same maximum length, return the one that appears first.
The problem can be solved using the sliding window technique. The core idea is to maintain a window and adjust its starting position whenever a repeated character is encountered, ensuring that all characters within the window are distinct.
Mathematically, if we denote by \( s[i:j] \) a substring of s from index \( i \) to \( j-1 \), we require that for every pair of indices \( k, l \) such that \( i \le k < l < j \), it holds that \( s[k] \neq s[l] \). The goal is to maximize \( j - i \).
inputFormat
The input consists of a single line containing the string s.
Note: The string can include spaces and special characters, and its length does not exceed 10,000 characters.
outputFormat
Output the longest substring of s that contains only distinct characters. The output should be printed in a single line.
## sampleabrkaabcdefghijjxxx
abcdefghij