think solution is in o(n)
Why time limit exceeded
submission id=#3753962
Firstly , consider it to be at-most K swaps instead of exactly K swaps.
Yes you can do it in linear time. Store locations of each digit. Now swap to get maximum element on the first position and so on…
Think greedily.