Overlapping Substrings
Submissions: 318   Accuracy:

27.02%

  Difficulty: Easy   Marks: 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"

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Hardik Gulati
Author: Ayush Saluja


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.