Doubt doubt doubt

Problem in code…???

https://ide.codingblocks.com/s/611159 Problem in code…???

https://ide.codingblocks.com/s/611159 Problem in code…???

Mistakes in your code

  // when k >= n
    if (k >= n)
    {
        sort(arr, arr + n, comparator);
        return;
    }

this is incorrect ,no of swaps may be greater than n

  1. and if you done swaping
    swap(arr[idx], arr[correct_idx]);
    you also have to update your map otherwise map will contain wrong entires

Reference Code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.