Sort a String
You are given a string $S$ of length $N$. You can apply the following operation on the string **any** number of times: - Choose an index $i$ $(1\le i \lt N)$, and swap $S_i$ with $S_{i+1}$, if $S_i$ and $S_{i+1}$ contain adjacent characters. For example, `a` and `b` are adjacent, `z` and `y` are adjacent, `x` and `y` are adjacent, while `c` and `e` are not adjacent. Note that `a` and `z` are **
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start