Medium Accuracy: 46.3%
Submissions: 8526 Points: 4
Given a string S with repeated characters. The task is to rearrange characters in a string such that no two adjacent characters are the same. Note: The string has only lowercase English alphabets and it can have multiple solutions. Return any one of them.
Input : str = "geeksforgeeks"Output: 1Explanation:All the repeated characters of the given string can be rearranged so that no adjacent characters in the string is equal. Any correct rearrangement will show a output of 1.
Input :str = "bbbbb"Output: 0Explanation : Repeated characters in the string cannot be rearranged such that there should not be any adjacent repeated character.
Your task :
You don't have to read input or print anything. Your task is to complete the functionrearrangeString() which takes the string as input and returns the modified string. If the string cannot be modified return "-1". Note:The generatedoutput is 1 if the string is successfully rearranged and is 0 if rearranging is not possible.
Expected Time Complexity : O(NlogN), N = length of String
Expected Auxiliary Space : O(number of english alphabets)