word of lowercase English letters. Rearrange its letters as if you were sweeping through the alphabet forward and backward, over and over.
- **Upward sweep:** go through the alphabet from a to z, and for every letter you still have left, take exactly one copy into the answer.
- **Downward sweep:** the same, but from z down to a.
Alternate upward and downward sweeps, starting with an upward one, until every letter of word is in the answer. Return the resulting string.word="bbaacc" → 'abccba'
The first upward pass takes one of each letter: a, b, c. That leaves a, b, c, and the downward pass takes c, b, a. Result: "abccba".
word="zebra" → 'aberz'
All letters are distinct, so the very first upward pass takes them all, giving the word in alphabetical order.
word="pppq" → 'pqpp'
Up: p, q. Down: p (no q left). Up: p. The result is "pqpp".
word) ≤ 500word consists of lowercase English lettersword="bbaacc"
'abccba'
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.