Question
Java Given a string S with repeated characters (only lowercase). The task is to rearrange characters in a string such that no two adjacent characters
Java
Given a string S with repeated characters (only lowercase).
The 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" (without quotes) if the generated string doesn't contains any same adjacent characters,
else if no such string is possible to be made print "0" (without quotes).
Constraints:
1 <= T <= 1001 <= length of string <= 104
Example:
Input:
3geeksforgeeksbbbabaaacdbbbbb
Output:110Exp
Please comment it . Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started