Input: arr[] = {2, 1, 13, 3, 7, 8, 21, 13, 12}, K = 2
Output: 2 1 3 7 13 8 13 21 12
The multiples of 2 in the array are 2, 8 and 12.
The elements that are in between the first two multiples of 2 are 1, 13, 3 and 7.
Hence, these elements in sorted order are 1, 3, 7 and 13.
Similarly, the elements between 8 and 12 in sorted order will be 13 and 21.
Input: arr[] = {11, 10, 9, 7, 4, 5, 12, 22, 13, 15, 17, 16}, K = 3
Output: 11 10 9 4 5 7 12 13 22 15 17 16