#C13765. Longest Unique Substring

    ID: 43339 Type: Default 1000ms 256MiB

Longest Unique Substring

Longest Unique Substring

Given a string s, find the longest substring of s that contains no repeating characters. The substring should be chosen such that its length is maximized. In case of multiple answers, return the substring that appears first in the string.

You are given multiple test cases. For each test case, output the longest substring with unique characters, followed by its length, separated by a single space. Note that if the substring is empty, simply output an empty string for the substring part.

The answer must be computed using an efficient algorithm (commonly known as the sliding window technique). All formulas (if any) should be written in LaTeX format. For example, the length of a substring computed from indices \(i\) to \(j\) is \(j-i+1\).

inputFormat

The input is read from standard input and it contains multiple test cases. The first line contains an integer T denoting the number of test cases. Each of the following T lines contains one string s.

For example:

6
abcabcbb
bbbbb
pwwkew

abcd aab

</p>

outputFormat

For each test case, output a line containing the longest substring without repeating characters followed by its length. The two outputs should be separated by a space and printed to standard output.

For example:

abc 3
b 1
wke 3
 0
abcd 4
ab 2
## sample
6
abcabcbb
bbbbb
pwwkew

abcd
aab
abc 3

b 1 wke 3 0 abcd 4 ab 2

</p>