#C13392. Longest Unique Substring

    ID: 42925 Type: Default 1000ms 256MiB

Longest Unique Substring

Longest Unique Substring

You are given a string s. Your task is to determine the length of the longest substring that contains only unique characters. In other words, you need to find the maximum length L such that there exists a substring s[i...j] (using 0-indexing) where every character appears only once.

This problem requires an efficient solution since the length of the string can be very large. A common approach is to use the sliding window technique with a hash map (or array) to track the occurrence of characters and update the window boundaries dynamically.

The formula for the length of a substring with starting index i and ending index j is given by: \( L = j - i + 1 \).

Make sure your solution reads input from standard input (stdin) and writes the answer to standard output (stdout).

inputFormat

A single line containing the string s is given. Note that s may contain spaces or other characters.

outputFormat

Output a single integer representing the length of the longest substring that contains all unique characters.## sample

abcabcbb
3