P18083 [GeeksforGeeks] String modification 1587115621
普及-
题目描述

Given a string with repeated characters, the task is to complete the function rearrangeString which rearrange characters in a string so that no two adjacent characters are same.
Note : It may be assumed that the string has only lowercase English alphabets and such transformation is always always possible.
Example 1:
Input:
S = aaabc
Output: 1
Explanation: We can transform the string
to abaca.
Example 2:
Input:
S = aaabb
Output: 1
Explanation: We can transform the string
to ababa.

Your Task:
Complete the function rearrangeString() which takes a string as an input parameter and returns the rearranged string. (The output will be 1 if the returned string has no adjacent character same, otherwise 0. Printing is done by the driver's code.)
Expected Time Complexity: O(N * log N), N = length of the string.
Expected Auxiliary Space: O(constant)
Constraints:
1< N < 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
S = aaabc
样例输出
1