#C9712. Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
Given a string s, your task is to determine the length of the longest substring that contains all unique characters (i.e. no duplicates). For example, if s is "abcabcbb", the answer is 3 because the substring "abc" is the longest with all distinct characters.
You need to process multiple test cases. The first input line contains an integer T representing the number of test cases. Each of the following T lines contains a string. For each test case, output the length of the longest substring without repeating characters.
The solution can be conceptualized using a sliding window technique. Mathematically, if the substring extends from index i to j, then its length is given by $j-i+1$. Update the start of the window when a repeated character is encountered.
inputFormat
The input is read from stdin and is formatted as follows:
- The first line contains an integer T indicating the number of test cases.
- The next T lines each contain a string.
For example:
3 abcabcbb bbbbb pwwkew
outputFormat
For each test case, print the length of the longest substring without repeating characters on a new line on stdout.
For the sample input above, the correct output is:
3 1 3## sample
3
abcabcbb
bbbbb
pwwkew
3
1
3
</p>