| 7 | space complexity: O(N) |
| 8 | ''' |
| 9 | class Solution: |
| 10 | def reorganizeString(self, S: str) -> str: |
| 11 | n = len(S) |
| 12 | a= [] |
| 13 | |
| 14 | for c,x in sorted((S.count(x), x) for x in set(S)): |
| 15 | if c > (n+1)/2: # not possible |
| 16 | return '' |
| 17 | a.extend(c*x) |
| 18 | |
| 19 | # empty list |
| 20 | ans = [None] * n |
| 21 | |
| 22 | # placing letters to make possible result |
| 23 | ans[::2], ans[1::2] = a[n//2:], a[:n//2] |
| 24 | return "".join(ans) |
| 25 | |
| 26 |
nothing calls this directly
no outgoing calls
no test coverage detected