Let a finite sequence $s=\{s_1,\dots,s_N\}$ (the characters of which are chosen from a finite set $\{c_1, \cdots, c_M\}$) be called "grouped" if for any $s_i=s_j$, $i<j$, we have $s_k=s_i=s_j$ for any $i<k<j$. For example, $\{a,a,c,c,c,b,b\}$ is grouped, where as $\{a,b,a,c,c,c,b\}$ is not.

What is the minimum number of swaps needed to make a given sequence $s$ 'grouped'? Is the computational complexity (in terms of the length of the string and the size of character set) of this problem known in literature?

A practical motivation might stem from (not completely sure though) the process of "disk de-fragmentation", where 'pieces' of the same file are grouped together in contiguous memory segments. .