#C5585. Longest Unique Substring

    ID: 49250 Type: Default 1000ms 256MiB

Longest Unique Substring

Longest Unique Substring

Given a string s, find the length of the longest substring without repeating characters.

This problem uses a sliding window technique. The window maintains a subset of characters that are all unique. When a duplicate character appears, adjust the window start appropriately. The answer is the maximum length encountered during the process.

Formally, let \(s\) be a string of length \(n\). We want to compute

\[ L = \max_{0 \leq i \leq j < n} \{ j - i + 1 \mid \text{All characters in } s[i\ldots j] \text{ are unique} \}\]

inputFormat

A single line string (s). The string can contain spaces and may be empty. Input is provided via standard input (stdin).

outputFormat

An integer representing the length of the longest substring of (s) that contains no repeating characters. The output should be printed to standard output (stdout).## sample

abcabcbb
3