Given a string S and you need to check whether S contains two non overlapping substrings "XY" and "YX" in any order or not.
The first line contains an integer T denoting the number of testcases. T lines following contains string S
Print "YES" or "NO" (in new line for each testcase) corresponding answer.
1<=length of the string S<=10^5
S=XYYX; Answer= YES;
From stated input string "XY" substring(1,2) and "YX" substring(3,4) can be easily separated without overlap so output is "YES"
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.