Given an array (or string of digits/characters), you can swap only adjacent elements. You must transform it so that all identical elements come together (in any order of groups) — i.e., every group is contiguous.
You want to minimize inversions (adjacent swaps) to achieve this "beautiful" grouped arrangement.
Input: 3 3 4 2 3 4 2 2 Output: 3 3 3 4 4 2 2 2 (or any permutation where each number forms a block)
This is similar to the minimum adjacent swaps to group identical elements problem.