#K38057. Complete String Deletion
Complete String Deletion
Complete String Deletion
Given a string \( S \) of length \( n \), determine whether it can be completely deleted by repeatedly removing any adjacent pair of identical characters. In each operation, if a pair is removed, the remaining parts of the string are concatenated, possibly forming new adjacent pairs.
For each test case, if it is possible to completely delete the string by applying this operation any number of times, print YES
; otherwise, print NO
.
inputFormat
The input is given from stdin and has the following format:
T n1 S1 n2 S2 ... nT ST
Here:
- T is the number of test cases.
- For each test case, the first value is an integer n, representing the length of the string, followed by the string S.
outputFormat
For each test case, output a line containing either YES
if the string can be completely deleted, or NO
otherwise. The output should be written to stdout.
4
4 abba
6 aabbcc
3 abc
5 abbba
YES
YES
NO
NO
</p>