DAYS
HOUR
MINS
SEC
Error
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.
Example 1:
Input : str = "geeksforgeeks" Output: 1 Explanation: 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.
Example 2:
Input : str = "bbbbb" Output: 0 Explanation: Repeated characters in the string cannot be rearranged such that there should not be any adjacent repeated character.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes