Back to Problem Solutions forum
According to the example:
input data:
6
31 41 59 26 53 58
answer:
2 2 2 1 0
But my code gives a different answer, 2 4 3 1 0
. I've tried to think it out and it seems that my answer is actually right:
31 41 59 26 53 58 -> max at 2
31 41 26 53 58 -> max at 4
31 41 26 53 -> max at 3
31 41 26 -> max at 1
31 26 -> max at 0
But according to the code checker, this answer is wrong, and I can't figure out why. May I get some explanation on this? (it actually looks like it goes the max-min-max-min way)
31 41 59 26 53 58 -> max at 2
When you find max element you switch it with the last one.
So array should be:
31 41 58 26 53
after first pass.
Oh, swapping. I feel kind of blind now. Thanks for making it clear for me!