Sorting in line

There are x x soldiers lined up in a row and sorted according to their heights. You want to reverse their order in the row in a minimum number of swaps. Any swap can be done by swapping of two soldiers next to each other.

-50 1 -49 50 49 -1

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Kunal Gupta
May 9, 2018

Swap every i t h i^{th} person with ( 99 i + 1 ) t h (99 -i +1 )^{th} person.
As, 99 99 is an odd number, so 5 0 t h 50^{th} person will be in place. Hence we require 49 49 swaps to sort them in reverse order

But the swaps are only allowed if the soldiers are standing next to each other

Log in to reply

Oh yes! Then I realise that, minimum swaps are n ( n 1 ) 2 \frac{n(n-1)}{2} which will give 0 0 as the answer

Kunal Gupta - 3 years ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...