Unlock Problem in STL

My first test case is failing due to TLE, can you please check why? Also, I read on a forum that in this question there should be at most k swaps not necessarily exactly k swaps. Which one is correct?

@duttrohan0302
Issue is with find max function
It takes 0(n) time to run and thus your algo becomes 0(n^2) while it should be 0(nlogn)
You can store the elements in decreasing order somewhere beforehand and use that info

Yeah you’re right it is at most K swaps

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.