Here's what matters: you need both the height and the position. Finding the maximum height isn't enough. You also need to know where that soldier is standing. This is exactly why pairs exist.
I'll show you the approach. Store each soldier as a pair (height, position). Find the maximum and minimum heights in the array. Note their positions. The tallest needs to move to the front, the shortest to the back.
Count the swaps: the tallest soldier at position needs swaps to reach the front. The shortest at position needs swaps to reach the back. But watch out for overlap.