Rearrange characters
Submissions: 6460   Accuracy:

47.07%

  Difficulty: Medium   Marks: 4
         

Given a string with repeated characters, task is to rearrange characters in a string such that no two adjacent characters are same.

Note : It may be assumed that the string has only lowercase English alphabets.


Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a single line containing a string of lowercase english alphabets.

Output:
For each test case in a new line print 1 if the generated sting doesn't contains any same adjacent characters, else if no such string is possible to be made print 0.
Constraints:
1<=T<=100
1<=length of string<=600

Example:

Input:
3

geeksforgeeks
bbbabaaacd
bbbbb


Output:
1

1
0

 

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

Author: harshitsidhwa


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

to report an issue on this page.