SHUFFLE - Editorial

This problem can be solved by checking differences of position of src element in original array and position of the src element in sorted array. This works for unique element. To solve for duplicate elements we just need to get lower bound and upper bound of duplicate element in sorted array and check if the difference is less than and equal to K [pos * K should be lied in the range, pos: position of src duplicate in sorted array].

My solution: CodeChef: Practical coding for everyone

I have used bubblesort to sort these k different lists and it is giving TLE , should i go with merge sort?

how this code fails to handle multiple occurences of elements?
https://www.codechef.com/viewsolution/38029919