Ron
Your decision is correct. This problem smells like Quicksort, right?
What you do with the Kth bit (all 0 to the left, 1 to the right) is called a section - you need to find non-local elements in pairs and change them. This is the process used in Hoare Selection and Quicksort, with a special classification of elements - there is no need to use a rotation element.
You forgot to indicate in the problem description how many elements are in the array (2 ^ k-2 or more), i.e. if repetition is allowed.
, . Hoare Selection ( ). , , , O (N). , , .
[ , Quicksort ( ), . , , O (N Lg (N)), .]
, : , , .
:
5132670 ( {0..7})
= 4
0132 | 675
675 ( {4..7})
= 2,
5 | 67
5 ( {4..5})
= 1
| 5
( {4}).
.