Someone please explain the solution of this problem . I’m not able to think of a solution.
Unlock! ( swap and permutation on codechef )
Start iterating fro 1 to N and if at ith index ,ai is not equal ith maximum then swap ai and other maximum and this will continue until you make maximum k swaps
but I’ve already implemented this algorithm and it is not getting accepted .
This questions asks for numerically largest permutation and not lexicographically.
I mean that if array is
4 , 2 , 6 , 9 , 12 , 10
and k=3
lexicographically largest permutation = 12, 10, 9, 6, 4, 2
numerically largest is : 9, 6, 4, 2, 12, 10
I have stated the question on codehef which is same as this question !
harsh instead of int array take input as string array and now compare now it will compare correspomds to their ascii value in which u get the correct numeric order
Yess I am saying for numerically greater one .
Just do it once if you still have problem them do ask me , I will send you the pseudo code