#K39247. Unique Prefix Segmentation Problem
Unique Prefix Segmentation Problem
Unique Prefix Segmentation Problem
Given a string (s) of length (n), let (P) be the longest prefix of (s) that contains only unique characters. The goal is to determine whether (P) is strictly shorter than (s). In other words, check if there exists a position where a character repeats, so that you can split (s) into a non-empty prefix (P) (with all unique characters) and a non-empty suffix. Output (YES) if such a split is possible, otherwise output (NO).
For example:
- For (s = \texttt{abcde}), the longest unique prefix is (\texttt{abcde}) (which is the entire string), so the answer is (NO).
- For (s = \texttt{aabbcc}), the longest unique prefix is (\texttt{a}) and the next character repeats, therefore the answer is (YES).
inputFormat
The input begins with an integer (T) representing the number of test cases. Each test case consists of a line containing an integer (n) and a string (s), where (n) is the length of (s).
outputFormat
For each test case, output a single line containing (YES) if it is possible to split (s) into a non-empty prefix with unique characters and a non-empty suffix (i.e. the unique prefix is not the entire string), or (NO) otherwise.## sample
4
5 abcde
6 aabbcc
4 abac
3 xyz
NO
YES
YES
NO
</p>