Let's say we got an array of size n with real numbers, and a natural number k. n must be multiple of k. We want to sort the array in a way that, when we divide this array into k subsets of equal size, all numbers of a subset should be less or equal than the numbers of the next right subset. In other words, given 1 <= i <= k, the numbers within subset i must be less or equal than the numbers of subset i + 1. However, the numbers within a subset does not need to be sorted.
For example, if we have k = 4 and the following array of size n = 12:
{10,8,2,12,3,9,4,5,11,1,7,6}
One valid solution could be:
{2,3,1,4,5,6,8,9,7,10,12,11}
As we can see all values of the subset {2,3,1} is less than {4,5,6}, which is less than {8,9,7}, and so on.
The condition here is that the complexity of the algorithm should not be worse than O(n log k). This problem is solved by either a Divide and Conquer approach or Min-heaps.
I tried many strategies, such as using the Quicksort partition algorithm and splitting the problem until reaching to a subproblem of size less than n/k, but at the end the complexity becomes O(n log n).
Any suggestions?