#K5716. Longest Non-Repeating Substring

    ID: 30359 Type: Default 1000ms 256MiB

Longest Non-Repeating Substring

Longest Non-Repeating Substring

You are given a string s. Your task is to find the longest substring of s which contains no repeating characters. In other words, among all substrings without any duplicate characters, you must choose the one with the maximum length. If there are multiple answers with the same length, return the one that appears first in s.

This problem can be solved using a sliding window approach. At each step, you maintain a window of characters such that no character is repeated. You adjust the window as you find duplicate characters. Mathematically, if you consider a substring from index i to j (inclusive), then for all indices k and l in [i, j], with k ≠ l, the condition s[k] ≠ s[l] must hold. In LaTeX, if we let the substring be \(s[i:j]\), then the condition is \[ s[i:j] \text{ is valid if } \forall \; k, l \in \{i, i+1, \ldots, j\},\; k \neq l \Rightarrow s[k] \neq s[l]. \]

inputFormat

The input is read from standard input. It consists of a single line containing the string s (with no spaces) for which you need to compute the longest substring without repeating characters.

outputFormat

Output to standard output the longest substring of s that does not contain any repeated characters. If there are multiple answers, output the one that appears first in the string.

## sample
abcabcbb
abc