#C9234. Longest Unique Substring
Longest Unique Substring
Longest Unique Substring
Given a string s, your task is to find the length of the longest substring which contains only unique characters (i.e. no repeated characters). This is a classic sliding window problem with applications in text analysis and pattern recognition.
The input begins with an integer T representing the number of test cases. For each test case, an integer n is provided which represents the length of the string (this value may be used for validation, but you can ignore it when processing the test case), followed by a string s on the next line. Your program should output the result for each test case on a new line.
Note: All formulas, if any, are represented in \( \LaTeX \) format. For example, the length of the substring is given by \( \text{result} = \max_{i \leq j} (j - i + 1) \) subject to the condition that all characters between indices \(i\) and \(j\) are distinct.
inputFormat
The first line of input contains an integer T (\(1 \leq T \leq 100\)), the number of test cases.
Each test case consists of two lines:
- The first line contains an integer n (the length of the string). Note: this value may be ignored while processing.
- The second line contains the string s (\(0 \leq |s| \leq 10^5\)).
outputFormat
For each test case, output a single integer indicating the length of the longest substring of s that contains only unique characters. Each result should be printed on a new line.
## sample3
7
abcabcbb
5
bbbbb
8
pwwkew
3
1
3
</p>