Wrong output for one test case


#1

for the input 4 : 701, 319, 695, 52
output should be 701 52 319 695 right??
But the expected output is coming as 701 695 52 319…What am I missing?


#2

I was having the same doubt first. But remember we are not forming a number here, we are only making permutations of the array elements (think of it as a descending order sequence).
It means that:
sequence 701, 52, 319, 695 is lesser in value than 701, 319, 695, 52 because when comparing the second element of the sequence 52< 319.
therefore according to this logic 701, 695, 52, 319 is just greater than the original sequence.
And the permutation 701, 695, 319,52 has the greatest possible value for the given sequence.