Question:medium

From one sequence of digits, another sequence of digits has to be formed as per the following rule:
Single switch: interchange of any two adjacent digits, where one such interchange counts as one step.

Using only single switching, what is the minimum number of steps required to change 51432 to 12345?

Show Hint

Count how many pairs of digits are out of their final relative order. That count is the minimum number of adjacent swaps needed.
Updated On: Jul 15, 2026
  • 6
  • 7
  • 8
  • 9
Show Solution

The Correct Option is B

Solution and Explanation

Instead of physically simulating every swap, this question can be answered directly by counting inversions, that is, pairs of digits that appear in the wrong relative order compared with the target sequence 1 2 3 4 5. Every single switch (adjacent swap) can remove at most one inversion, so the minimum number of steps equals the total number of inversions in the starting sequence.

The starting sequence is 5, 1, 4, 3, 2. Compare every pair of digits, in the order they appear, and mark a pair as an inversion if the left one is bigger than the right one:

  1. 5 with 1, 4, 3, 2: the digit 5 is bigger than all four digits that come after it, giving 4 inversions.
  2. 1 with 4, 3, 2: 1 is smaller than all three, so 0 inversions here.
  3. 4 with 3, 2: 4 is bigger than both, giving 2 inversions.
  4. 3 with 2: 3 is bigger than 2, giving 1 inversion.

Adding these up: $4 + 0 + 2 + 1 = 7$.

Let's summarize:

  • An adjacent swap can fix exactly one out-of-order pair at a time, never more.
  • The sequence 5 1 4 3 2 has 7 such out-of-order pairs against the target 1 2 3 4 5.

So the minimum number of single switch steps needed is 7, which matches option (b).

Was this answer helpful?
0


Questions Asked in SNAP exam