You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DSA Crack Sheet/README.md
+1
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,7 @@
86
86
-[Longest Common Subsequence](https://practice.geeksforgeeks.org/problems/longest-common-subsequence-1587115620/1"view question") - [Cpp Solution](./solutions/Longest%20Common%20Subsequence.cpp)
87
87
-[Program to generate all possible valid IP addresses from given string](https://www.geeksforgeeks.org/program-generate-possible-valid-ip-addresses-given-string/"view topic")
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.
6
+
7
+
Note : It may be assumed that the string has only lowercase English alphabets.
8
+
9
+
Input:
10
+
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.
11
+
12
+
Output:
13
+
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).
14
+
15
+
Constraints:
16
+
1 <= T <= 100
17
+
1 <= length of string <= 104
18
+
19
+
Example:
20
+
Input:
21
+
3
22
+
geeksforgeeks
23
+
bbbabaaacd
24
+
bbbbb
25
+
Output:
26
+
1
27
+
1
28
+
0
29
+
30
+
Explanation:
31
+
Testcase 1: All the repeated characters of the given string can be rearranged so that no adjacent characters in the string is equal.
32
+
Testcase 3: Repeated characters in the string cannot be rearranged such that there should not be any adjacent repeated character.
0 commit comments