[Question]
  [
If you sort a string you'll typically get something like:
```
         ':Iaaceeefggghiiiiklllllmnnooooprrssstttttuuyyyy
```
Yes, that was the first sentence sorted.
As you can see, there are a lot of repeated characters, `aa`, `eee`, `ttttt`, 9 spaces and so on.
If we add `128` to the ASCII-value of the first duplicate, `256` to the second, `384` to the third and so on, sort it again and output the new string (modulus 128 to get the same characters back) we get the string:
```
 ':Iacefghiklmnoprstuy aegilnorstuy egilosty iloty lt    
```
(Note the single leading space and the 4 trailing spaces).
The string is "sequentially sorted" `<space>':I....uy`, `<space>aeg....uy`, `<space>egi....ty`, `<space>iloty`, `<space>lt`, `<space>`, `<space>`,`<space>`, `<space>`.
It might be easier to visualize this if we use a string with digits in it. The string `111222334` will when "sorted" be: `123412312`.
## Challenge:
To no surprise, the challenge is to write a code that sorts a string according to the description above.
You can assume that the input string will contain only printable ASCII-characters in the range 32-126 (space to tilde).
---
**Test cases:**
```
**Test cases:**
 *:Tacest*es*s*
If you sort a string you'll typically get something like:
 ':Iacefghiklmnoprstuy aegilnorstuy egilosty iloty lt    
Hello, World!
 !,HWdelorlol
#MATLAB, 114 bytes
 #,14ABLMTbesty 1A
f=@(s)[mod(sort(cell2mat(cellfun(@(c)c+128*(0:nnz(c)-1),mat2cell(sort(s),1,histc(s,unique(s))),'un',0))),128),''];
'()*+,-0128:;=@[]acdefhilmnoqrstuz'(),0128@acefilmnorstu'(),12celmnostu'(),12celnstu(),clnst(),cls(),cs(),()()()()
```
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in *each language* counted in bytes will win[ref](http://meta.codegolf.stackexchange.com/a/10132/31516).
  
[Answer]
# Pyth, 5 bytes
```
s.T.g
```
[Test suite](https://pyth.herokuapp.com/?code=s.T.g&test_suite=1&test_suite_input=%22%2a%2aTest+cases%3A%2a%2a%22%0A%22If+you+sort+a+string+you%27ll+typically+get+something+like%3A%22%0A%22Hello%2C+World%21%22%0A%22%23MATLAB%2C+114+bytes%22%0A%22f%3D%40%28s%29%5Bmod%28sort%28cell2mat%28cellfun%28%40%28c%29c%2B128%2a%280%3Annz%28c%29-1%29%2Cmat2cell%28sort%28s%29%2C1%2Chistc%28s%2Cunique%28s%29%29%29%2C%27un%27%2C0%29%29%29%2C128%29%2C%27%27%5D%3B%22&debug=0)
Very straightforward: Group and sort, transpose, concatenate.
```
s.T.g
s.T.gkQ    Implicit variables
   .gkQ    Group the input input lists of elements whose values match when the
           identity function is applied, sorted by the output value.
 .T        Transpose, skipping empty values. This puts all first characters into
           a list, then all second, etc.
s          Concatenate.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
ĠZị
```
[Try it online!](https://tio.run/nexus/jelly#JYw/TsMwGMX3nOJDDLFdI9URAwqq1DKBBFsl1KIOwXVaC8eGfPYQRpYOvUQP0LFbx3KRcpFgq9v783uv/93Nz8dtfz4eTpu/n/2s7xmbKvQgK1RYMpY91dC5AOhaDxWgb7VdpSQ3Bnz3qWVlTAcr5SPSKL9OtdEfqswelTGOw6trzfIqu36ZTJ8nDxyEuIX3zivM6tGYIH1r3JKkeyLjoGiqi6iDJWMiqRyI4o6RYWntd7Q3gvKIFAm5rJBywdcavSTIg9VfQcWMUp4Hm/NhUvEh2nxx/w8 "Jelly – TIO Nexus")
### How it works
Oh boy, this challenge was all but made for Jelly.
The *group* atom (`Ġ`) takes an array1 as input and groups indices that correspond to identical elements of the array. The array of index groups is sorted with the corresponding elements as keys, which is precisely the order we require for this challenge.
Next, the *zip* atom (`Z`) transposes rows and columns of the generated (ragged) matrix of indices. This simply consists of reading the columns of the matrix, skipping elements that are not present in that column. As a result, we get the first index of the character with the lowest code point, followed by the first index of the character with the second lowest code point, … followed by the second index of the character with the lowest code point, etc.
Finally, the *unindex* atom (`ị`) retrieves the elements of the input array at all of its indices in the generated order. The result is a 2D character array, which Jelly flattens before printing it.
---
1 Jelly doesn't have a *string* type, just arrays of characters.
[Answer]
# Python 3, ~~109~~ ~~105~~ ~~104~~ ~~103~~ ~~99~~ ~~93~~ ~~90~~ ~~88~~ ~~81~~ ~~79~~ 69 bytes
*2 bytes saved thanks to FlipTack*
*7 bytes saved because flornquake caught my dumb error*
*2 bytes saved thanks to xnor*
*10 bytes saved thanks to Dennis*
```
a=[*input()]
while a:
    for c in sorted({*a}):print(end=c);a.remove(c)
```
## Explanation
We start by converting our string to a list using a splat and storing that list in a variable `a`. Then while our `a` is not the empty list we go through each unique member of `a` in sorted order, print it and remove a copy of that character from the list.
Each iteration prints thus prints one copy of each character present in `a`.
[Answer]
## Haskell, 44 bytes
```
import Data.List
concat.transpose.group.sort
```
Usage example: 
```
Prelude Data.List> concat.transpose.group.sort $ "If you sort a string you'll typically get something like:"
" ':Iacefghiklmnoprstuy aegilnorstuy egilosty iloty lt    "
```
Sort, group equal chars to a list of strings (e.g. `"aabbc"` -> `["aa","bb","c"]`), transpose and flatten into a single string, again.
[Answer]
# [Python 2](https://docs.python.org/2/), 75 bytes
```
lambda s:`zip(*sorted((s[:i].count(c),c)for i,c in enumerate(s)))[1]`[2::5]
```
[Try it online!](https://tio.run/nexus/python2#JY9PT8MwDMXP9FMYcahTAlorJqGgSRsnkOA2iUOptixNt4g0Kfkj1H35kWg3P/v3nu0BVvB90Xw89Bw825/VhJW3Lsge0bdMdY/CRhNQECrIYB0oKkAZkCaO0vEg0RNC2rrbtw1jy@6SmV0mHDdHiUvCipvJKRNgQMf/dspMMSAhl6raSh9AcC89q6rifYDZRsjLId0SkueYO6XWEOZJCa71DEcZEjLKcMpjrX4kK96k1pbCl3W6vy3uPjfbj80rhbp@gsMcpC@G1Tqd2Y62xxyPIhmakV@LIRpcp//Efd08V7hgxpyTfKgJTUiTkavLE1rTk/JBoKfRqN94fZ6W0ZR0kauUkGTZvfwD "Python 2 – TIO Nexus")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~21~~ 20 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319)
```
t[0~⍨∊⍉(⊂⍋∪t)⌷⊢⌸t←⍞]
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKO94H9JtEHdo94Vjzq6HvV2ajzqanrU2/2oY1WJ5qOe7Y@6Fj3q2VHyqG3Co955sSD1/xXAoIDLM02hMr9UoTi/qEQhUaG4pCgzLx0kop6To1BSWZCZnJiTU6mQnloCVJKbWpIBks7JzE61AgA "APL (Dyalog Unicode) – Try It Online")
`t[`...`]` index *t* (to be defined shortly) with...
 `0~⍨` zeros removed from
 `∊` the enlisted (flattened)
 `⍉` transposed
 `(⊂`…`)⌷` reordered using…
  `⍋` the indices which would sort
  `∪` the unique letters of
  `t` *t* (to be defined shortly)
 `⊢⌸t` keyed\* *t*, which has the value of
  `⍞` prompted text input
[TryAPL online!](http://tryapl.org/?a=%u2359%u2190%27If%20you%20sort%20a%20string%20you%27%27ll%20typically%20get%20something%20like%3A%27%20%u22C4%20t%5B0%7E%u2368%u220A%u2349%28%u22A2%u2338t%29%5B%u234B%u222At%u2190%u2359%3B%5D%5D&run)
---
\* `⊢⌸t` creates a table where the rows (padded with zeros for a rectangular table) list each unique letters' indices in *t*.
[Answer]
# C, ~~109~~ ~~106~~ ~~105~~ ~~104~~ ~~102~~ ~~100~~ ~~97~~ ~~98~~ ~~96~~ 91 Bytes
~~Back up to 98 Bytes, needed to initialize j to make f(n) re-useable~~
~~Down to 96 Bytes using puts in place of strlen B-)~~ 
It's strange I had to back to strlen but I got rid of the for(;i++;) loop so now it's down to 91 Bytes. Apparently the man page for puts reads;
```
"RETURNS
   If successful, the result is a nonnegative integer; otherwise, the result is `EOF'."
```
... I was lucky it was working in the first place
```
char*c,i,j;f(m){for(j=strlen(m);j;++i)for(c=m;*c;c++)if(*c==i){*c=7,putchar(i),j--;break;}}
```
test code...
```
main(c,v)char**v;
{
    char test[] = "If you sort a string you'll typically get something like: ";
    char test2[] = "Hello, World!";
    f(test);puts("");    
    f(test2);puts("");    
}
```
Here are a few test cases, now it's time to golf this down
```
C:\eng\golf>a.exe
 ':Iacefghiklmnoprstuy aegilnorstuy egilosty iloty lt
 !,HWdelorlo
```
[Answer]
# Mathematica, ~~68~~ ~~60~~ 59 bytes
```
Split[Characters@#~SortBy~ToCharacterCode]~Flatten~{2}<>""&
```
Accepts a String. Outputs a String.
**If list of characters were allowed (46 bytes):**
```
Split[#~SortBy~ToCharacterCode]~Flatten~{2,1}&
```
**Version using `Sort` (40 bytes):**
```
Split@Sort@Characters@#~Flatten~{2}<>""&
```
This version cannot be my answer because `Sort` cannot be used here; `Sort` sorts by canonical order, not by character code.
[Answer]
# Python 2, ~~77~~ 76 bytes
```
d={}
def f(c):d[c]=r=d.get(c,c),;return r
print`sorted(input(),key=f)`[2::5]
```
Takes a quoted string as input from stdin.
[Try it online!](https://tio.run/nexus/python2#FYxBCsMgEEX3OcWQTRUki0I3Fg/QM4RAgo6pxBox40JKz251@/77rxr1/Q0GLVimuTSzXlRSZtqRmBaai2dCyilAGmJygdbrTISGuRAzMS4OLMrydb5L@VhqHV8WypmhW7DBRe2zd3LzHqhEpzfvC7R6Uz5I7z57d6Ac6x8)
[Answer]
## JavaScript (ES6), 79 bytes
```
f=s=>s&&(a=[...new Set(s)]).sort().join``+f(a.reduce((s,e)=>s.replace(e,``),s))
```
```
<input oninput=o.textContent=f(this.value)><pre id=o>
```
Works by extracting the set of unique characters, sorting it, removing them from the original string, and recursively calculating the sort of the rest of the string. 81 byte solution that I found interesting:
```
f=s=>s&&(s=[...s].sort().join``).replace(r=/(.)(\1*)/g,"$1")+f(s.replace(r,"$2"))
```
[Answer]
## [J](http://jsoftware.com/), ~~16~~ 15 bytes
```
/:+/@(={:)\;"0]
```
This is a verb that takes and returns one string.
[Try it online!](https://tio.run/nexus/j#@5@mYGuloG@lre@gYVttpRljrWQQ@z81OSNfIU1BPTExKSk5JRUI1f8DAA "J – TIO Nexus")
Miles saved a byte, thanks!
## Explanation
Nothing too fancy here: sort primarily by order of occurrence, secondarily by char value.
```
/:+/@(={:)\;"0]  Input is y.
          \      Map over prefixes:
  +/              Sum
    @(   )        of
      =           bit-array of equality
       {:         with last element.
                 This gives an array of integers whose i'th element is k
                 if index i is the k'th occurrence of y[i].
           ;     Pair this array
            "0   element-wise
              ]  with y
/:               and sort y using it as key.
```
[Answer]
# [Brainf\*ck](https://github.com/TryItOnline/tio-transpilers), ~~458~~ 226 bytes
```
,[>>>>>>,]<<<<<<[[-<<<+<<<]>>>[>>>[>>>>>>]<<<[>>--[<->--]<-<[>->+<[>]>[<+>-]<<[<]>-]>>.[[-]<]<<<[[>>>>>>+<<<<<<-]<<<]>>>>>>]>>>[>>>[>>>>>>]<<<[>>--[<->--]<-<[>->+<[>]>[<+>-]<<[<]>-]>>[-<+<+>>]<[->>+<<]<[<<<<<<]>>>]>>>]]<<<<<<]
```
[Try it online! - BF](https://tio.run/nexus/brainfuck#pU/RDoIwDPwcNrca4MnoXPiPpg8GIZLAiA5e/Hm8Df7AJm2ut9612yz7HFZcDmZCNUgBy0ci0jsgETtCFUdoyRtU8eyMB@UYKoLwDBtxWXLIzW6fhrJzcvxjAa40oCBiyuYA@wY5nOX4kGxbf29U1DzNTxXnz6Labhzr6bGDfg2qUa1uTVVfTqq8hvBFS5W2GKnTyK6K2lb2NcSlVdGuYXivHTitbbGGwpYJwQFtIbcf "Brainf*ck – TIO Nexus")
# [Numberwang](https://esolangs.org/wiki/Numberwang_(brainfuck_derivative)), ~~262~~ 226 bytes
```
8400000087111111442111911170004000400000071114002241202271214020914070419027114170270034427171114400000091111112711170000007000400040000007111400224120227121402091407041902711417027004219190071420091171411111170007000771111117
```
[Try it online! - NW](https://tio.run/nexus/numberwang#pU/tCsIwDHyctVqhiYWuirD3EH9I3XAwO7TbH19@Xj/ewEDC5Zq7pFtrdI7WUg5jGNUhLVhTE5HeAZkNMaolRsvaoVptyGlQZKBiCI@wsZQlVe6KfRrKzsnxjwW40oGCyHA2BygbbHW29UN224ZLJ6K8vuaHiPNnEb6fJn7dCxjWIDrhpd8TtzuhTyF80R5IKoxwGimqKBWp5xgXL6Jaw/hee3BSqmYNjdIJwQFtczv/AA "Numberwang – TIO Nexus")
I put both of these here because they are identical code.
[Answer]
# PHP, 83 bytes
```
for($s=count_chars($argv[1]);$s=array_filter($s);$c%=128)echo$s[++$c]--?chr($c):'';
```
Unfortunately you can't have `unset` in a ternary so I need to use the annoyingly long `array_filter`.  
Use like:
```
php -r "for($s=count_chars($argv[1]);$s=array_filter($s);$c%=128)echo$s[++$c]--?chr($c):'';" "If you sort a string you'll typically get something like:"
```
[Answer]
## Python 2, 70 bytes
```
f=lambda s,i=0,c='':s[i>>7:]and(s.count(c)>i>>7)*c+f(s,i+1,chr(i%128))
```
[Try it online](https://tio.run/nexus/python2#RU27CoMwFN39iiCUJrWIFkqLoHtnx9IhjUm9NA/JvQ75ehunHjjLeW6mt9K9J8nwDH3T4ROG4dq9pJ841iqsnriaI4dDe7kLMWT3Jk5/pTI8F6tWbOCWEIlhwiKzRk1RqzUiBG/BAfG2yRDF2JcPw1JYGe75fEwR/GdXjtYySgsoaW1iH53XgtM077aFr@7KYslZYoaPYvsB)
This is very inefficient. The test link changes the `i>>7` to `i>>5` and sets the recursion limit to 10000. Assumes the inputs only has ASCII values up to 126.
Uses the div-mod trick to iterate through two loops: minimum counts `i/128` in the outer loop and ASCII values `i%128` in the inner loop. Includes a character `c` with the given ASCII value if the number of times it appears in the string is at least its minimum count.
The code uses a trick to simulate the assignment `c=chr(i%128)` so that it can be referenced in the expression `(s.count(c)>i>>7)*c`. Python `lambda`s do not allow assignment because they only take expressions. Converting to a `def` or full program is still a net loss here. 
Instead, the function pushes forward the value `chr(i%128)` to the next recursive call as an optional input. This is off by one because `i` has been incremented, but doesn't matter as long as the string doesn't contain special character `'\x7f'` (we could also raise 128 to 256). The initial `c=''` is harmless.
[Answer]
# [V](https://github.com/DJMcMayhem/V), ~~37~~ 36 bytes
Thanks @DJMcMayhem for the byte!
```
Í./&ò
dd:sor
Íî
òÍ¨.©¨±«©±À!¨.«©/±³²
```
[Try it online!](https://tio.run/nexus/v#@3@4V09f7fAmrpQUq@L8Iq7DvYfXcR3edLj30Aq9QysPrTi08dBqIL3xcIMiSATI1gcKbT606f9/zzSFyvxSBaCuEoVEheKSosy8dJCIek6OQkllQWZyYk5OpUJ6aglQSW5qSQZIOiczO9UKAA "V – TIO Nexus")
Not sure I like the regex at the end, but I needed to make the `ò` break somehow.
### Explain
```
Í./&ò                    #All chars on their own line
dd:sor                   #Delete empty line, sort chars
Íî                       #Join all lines together s/\n//
òÍ¨.©¨±«©±À!¨.«©/±³² #until breaking s/\v(.)(\1+)\1@!(.+)/\3\2\1
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `d`, 3 bytes
```
sĠ∩
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJkIiwiIiwic8Sg4oipIiwiIiwiSGVsbG8sIFdvcmxkISJd)
```
s   # Sort
 Ġ  # Group run lengths
  ∩ # Transpose
    # (d flag) take deep sum
```
[Answer]
# [Perl 6](http://perl6.org/), 68 bytes
```
{my \a=.comb.sort;[~] flat roundrobin |a.squish.map({grep *eq$_,a})}
```
I was a little surprised to find that there's no built-in way to group like elements in a list. That's what the squish-map bit does.
[Answer]
# JavaScript (ES6), ~~77~~ 75 bytes
```
s=>(a=[],x={},[...s].sort().map(c=>a[x[c]=n=-~x[c]]=(a[n]||'')+c),a).join``
```
Stable sorts the lexicographically sorted string by nth occurence
```
F=s=>(a=[],x={},[...s].sort().map(c=>a[x[c]=n=-~x[c]]=(a[n]||'')+c),a).join``
const update = () => {
  console.clear();
  console.log(F(input.value));
};
input.oninput = update;
update();
```
```
#input {
  width: 100%;
  box-sizing: border-box;
}
```
```
<input id="input" type="text" value="         ':Iaaceeefggghiiiiklllllmnnooooprrssstttttuuyyyy" length=99/>
<div id="output"></div>
```
[Answer]
# [Perl 6](http://perl6.org/), 54 bytes
```
{[~] flat roundrobin |.comb.classify(~*){*}.sort»[*]}
```
Explanation:
* `{ }`: A lambda that takes one argument -- e.g. `21211`.
* `.comb`: Split the input argument into a list of characters -- e.g. `(2,1,2,1,1)`.
* `.classify(~*)`: Group the characters using string comparison as the grouping condition, returning an unordered Hash -- e.g. `{ 2=>[2,2], 1=>[1,1,1] }`.
* `{*}`: Return a list of all values of the Hash -- e.g. `[2,2], [1,1,1]`.
* `.sort`: Sort it -- e.g. `[1,1,1], [2,2]`.
* `»[*]`: Strip the item containers the arrays were wrapped in due to being in the hash, so that they won't be considered as a single item in the following step -- e.g. `(1,1,1), (2,2)`.
* `roundrobin |`: Zip the sub-lists until all are exhausted -- e.g. `(1,2), (1,2), (1)`.
* `flat`: Flatten the result -- e.g. `1, 2, 1, 2, 1`.
* `[~]`: Concatenate it to get a string again -- e.g. `12121`.
(Credit for the `roundrobin` approach goes to [Sean's answer](https://codegolf.stackexchange.com/a/106412/14880).)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 15 bytes
```
{.¡"ä"©¹g×«øJ®K
```
[Try it online!](https://tio.run/nexus/05ab1e#ASkA1v//ey7CoSLDpCLCqcK5Z8OXwqvDuErCrkv//yoqVGVzdCBjYXNlczoqKg)
or as a
[Test suite](https://tio.run/nexus/05ab1e#JYy7TsMwGIX3PMVPGWIbg@qIAQUhtUxct0odEENwndTCsSG/jWTgPZiRWBASM3PyYMFRt3P5zhnfX@LbUf85G75m/Xdsho/@Z/i76n@v@TgytlLoQVaosGQsu6whugDoOg8VoO@0baYkNwZ8fNKyMiZCo3xCWuW3U230oyqzC2WM47B2ndnsZfu3y9XN8pyDEMfwEL3CrD5bEKR3rduQ6Z7INCjaaifqYMmCSCoPRHHCyLy09jXZQ0F5QooJ2a2QcsG3Gr0kyIPVz0GljFKeB5vz@aTSQ7L5/ek/)
**Explanation**
```
{                # sort input
 .¡              # group by equal elements
   "ä"©          # push "ä" and store a copy in the register
       ¹g×       # repeat the "ä" input-nr times
          «      # concatenate the result to each string in the grouped input
           ø     # zip
            J    # join to string
             ®K  # remove all instances of "ä" in the string
```
10 of the 15 bytes are for getting around 05AB1E's way of handling zipping strings of different length.
[Answer]
# FSharp, ~~194~~ ~~190~~ ~~170~~ ~~140~~ 133 bytes
```
let f=Seq.map
let(@)=(>>)
f [[email protected]](/cdn-cgi/l/email-protection) id@f([[email protected]](/cdn-cgi/l/email-protection)((*)128@(+)))@[[email protected]](/cdn-cgi/l/email-protection)@f((%)@(|>)128@byte)@Array.ofSeq@f char
```
Using Seq instead of Array saves a couple of bytes
Defining a shorter name, and using another maps to avoid a `(fun ->)` block
It turns out F# can map a char to an in, so removing the shortened name of System.Text.Encoding.ASCII, and adding in another map saves me 20 bytes!
Returning a char array instead of a string, saves me 30 bytes!
I no longer need to make sure it's a string, saves me 7 bytes
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
ΣTgO
```
[Try it online!](https://tio.run/##yygtzv7//9zikHT/////e6YpVOaXKhTnF5UoJCoUlxRl5qWDRNRzchRKKgsykxNzcioV0lNLgEpyU0syQNI5mdmpVgA "Husk – Try It Online")
## Explanation
```
ΣTgO
   O Order
  g  group
 T   Transpose
Σ    join
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 71 bytes
```
f=x=>x&&[...x].filter(k=c=>k[c]?![h+=c]:k[c]=1,h='').sort().join``+f(h)
```
[Try it online!](https://tio.run/##FYrdDoIgFIBfhbxQmMXWrRt23TMwNxmBoCdwcGr69BSX38@qvirr5He8hfgypVhxiPFoW8k5PyZuPaBJdBNajJvU0@MiXS/0NFQQ96sTXcd4jgkp42v0YZ57Sx0rOoYcwXCIC7W0eVpyxg@pI1EkY/JhqaYDIHjuXiuAkywG/8vboKsZ/GaGhrHyAw "JavaScript (Node.js) – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-P`](https://codegolf.meta.stackexchange.com/a/14339/), 4 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Input as a character array, output as a string.
```
ü Õc
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVA&header=cQ&code=/CDVYw&input=IklmIHlvdSBzb3J0IGEgc3RyaW5nIHlvdSdsbCB0eXBpY2FsbHkgZ2V0IHNvbWV0aGluZyBsaWtlOiI)
```
ü Õc     :Implicit input of character array
ü        :Group & sort
  Õ      :Transpose
   c     :Flatten
         :Implicitly join & output
```
[Answer]
# JavaScript (ES6), 114 bytes
Separated with newline for clarity, not part of byte count:
```
s=>[...s].map(a=>(m[a]=-~m[a])*128+a.charCodeAt(),m={})
.sort((a,b)=>a-b).map(a=>String.fromCharCode(a%128)).join``
```
## Demo
```
`**Test cases:**
 *:Tacest*es*s*
If you sort a string you'll typically get something like:
 ':Iacefghiklmnoprstuy aegilnorstuy egilosty iloty lt    
Hello, World!
 !,HWdelorlol
#MATLAB, 114 bytes
 #,14ABLMTbesty 1A
f=@(s)[mod(sort(cell2mat(cellfun(@(c)c+128*(0:nnz(c)-1),mat2cell(sort(s),1,histc(s,unique(s))),'un',0))),128),''];
'()*+,-0128:;=@[]acdefhilmnoqrstuz'(),0128@acefilmnorstu'(),12celmnostu'(),12celnstu(),clnst(),cls(),cs(),()()()()`.split`\n\n`.map(s=>(p=s.split`\n`,console.log(`${p[0]}\n\n${r=f(p[0])}\n\nmatch: ${r==p[1]}`)),
f=s=>[...s].map(a=>(m[a]=-~m[a])*128+a.charCodeAt(),m={}).sort((a,b)=>a-b).map(a=>String.fromCharCode(a%128)).join``)
```
[Answer]
## Clojure, 79 bytes
```
#(for[V[(group-by(fn[s]s)%)]i(range 1e9)k(sort(keys V))c[(get(V k)i)]:when c]c)
```
An anonymous function, returns a sequence of characters. Supports up-to 10^9 repetitions of any characters, which should be plenty.
[Answer]
## [Retina](https://github.com/m-ender/retina), 24 bytes
```
O`.
O$#`(.)(?=(\1)*)
$#2
```
[Try it online!](https://tio.run/nexus/retina#@@@foMflr6KcoKGnqWFvqxFjqKmlyaWibPT/v2eaQmV@qUJxflGJQqJCcUlRZl46SEQ9J0ehpLIgMzkxJ6dSIT21BKgkN7UkAySdk5mdaqUAAA "Retina – TIO Nexus")
[Answer]
# Ruby, 59+1 = 60 bytes
Adds one byte for the `-n` flag. Port of @PatrickRoberts' dictionary solution.
```
d={};print *$_.chars.sort_by{|c|d[c]||=0;c.ord+128*d[c]+=1}
```
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 6 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
∾·⊒⊸⊔∧
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAg4oi+wrfiipLiirjiipTiiKcKCj7ii4jiiJhGwqgg4p+oCiAgIioqVGVzdCBjYXNlczoqKiIKICAiSWYgeW91IHNvcnQgYSBzdHJpbmcgeW91J2xsIHR5cGljYWxseSBnZXQgc29tZXRoaW5nIGxpa2U6IgogICJIZWxsbywgV29ybGQhIgogICIjTUFUTEFCLCAxMTQgYnl0ZXMiCiAgImY9QChzKVttb2Qoc29ydChjZWxsMm1hdChjZWxsZnVuKEAoYyljKzEyOCooMDpubnooYyktMSksbWF0MmNlbGwoc29ydChzKSwxLGhpc3RjKHMsdW5pcXVlKHMpKSksJ3VuJywwKSkpLDEyOCksJyddOyIK4p+p)
sort, group by occurrence count, join.
[Answer]
# [Factor](https://factorcode.org) + `grouping.extras`, 48 bytes
```
[ natural-sort [ ] group-by values round-robin ]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TVDLTsMwEBTXfsVSDnngoKbiUKVCarkAEiAhijhUObiu01o4dvADERBfwqUX-AD-Br6GTV0kfPHM7Myudt8_K8qcNpufvZu724vrswKsNk6oFayM9g2CI_7sDLVArdXMguWPnivG_6E_h9DQGO5c2xihHIx7rz3A10_TGbcOGLXcFmnaD-pFBa3223FAwTrTDUUlkhKwhWBUyhZW3KGl5m7dlaV44MUuf86l1ATutZHL_Z12cDWdXU5PCeT5MSxax-2uUJ1MYpvMa72Mu4Exw_CwpgFUXsWTmCXsMB-O0nhQKPWCNMsTgpZhZwkpm5CcrIV1LLbEK4H7o5YkJPIqIoMOYQekUTnu994-vKuy0fdgDoo6b6jMtsvOoQzHzRYtPFHp8ZZI1TIzeiEUlCH3VdMGveGWJXDK1qGw2YT_Fw)
* `natural-sort` Sort the input
* `[ ] group-by values` Group like contiguous elements, e.g. `"aabbc"` -> `{ "aa" "bb" "c" }`
* `round-robin` One from each group in order, until there are no elements left. e.g. `{ "aa" "bb" "c" }` -> `"abcab"`
]