The Non-repetitive String
Submissions: 1298   Accuracy:

42.48%

  Difficulty: Easy   Marks: 2

Shreyansh has been given a string for evaluation by his teacher. He needs to find out whether the given string is non-repetitive or not.
A non-repetitive string is defined as a string which does not contain any different character between 2 same characters (Refer example for explanation).

Input : 
The first line of input contains a single integer T denoting the number of test cases. Each test case contains a string S which consists only of upper-case English alphabets.

Output : 
For each test case, print 1 if the string is non-repetitive, else print 0 in a new line.

Constraints : 
1 <= T <= 200
2 <= Length of String S <= 10^4

Example : 
Input : 

3
AAABCDD
AABBAA
ABCDA

Output : 
1
0
0

Explanation : 
Case 1 : 
AAABCDD
Here no different character is placed between 2 same characters.

Case 2 : 
AABBAA
Here 2 B's are placed between 2 A's, so this is not a non-repetitive string.

Case 3 : 
ABCDA
Here 1 B, 1 C, 1 D are placed between 2 A's, so this is not a non-repetitive string.

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

Author: goyalanubhav11


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.