Overlapping Substrings
Easy Accuracy: 27.61% Submissions: 348 Points: 2

Given a string S and you need to check whether S contains two non overlapping substrings "XY" and "YX" in any order or not.

Input:
The first line contains an integer T denoting the number of testcases. T lines following contains string S


Output:
Print "YES" or "NO" (in new line for each testcase) corresponding answer.


Constraints:
1<=T<=40
1<=length of the string S<=10^5

Example:

Input:
3
XYYX
CXXYXDDXXYDYC
ABYFAB

Output:
YES
YES
NO

Explanation:

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"

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.