text: Increment sum by number of swaps required i . e . position of next ' [ ' - current position
code: sum += pos . get ( p ) - i ; char temp = S [ i ] ; S [ i ] = S [ pos . get ( p ) ] ; S [ pos . get ( p ) ] = temp ; ++ p ;