Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.
Return any possible rearrangement of s or return “” if not possible.
Example 1:
1 | Input: s = "aab" |
Example 2:
1 | Input: s = "aaab" |
Constraints:
1 | 1 <= s.length <= 500 |
Approach
1 | Find the char with the highest fequency. Fill the string with the char every 2 indixes. Fill the rest of the chars. |
Algorithm
1 | 1. Count the frequency of each char and find the char with the highest frequency. |
Implementation
1 | char * reorganizeString(char * s){ |