Question:medium

From one sequence of digits, another sequence of digits has to be formed as per the following rule:
Random switch: interchange of any two digits, regardless of where they sit in the sequence, where one such interchange counts as one step.

Using only random switching, what is the minimum number of steps required to change 653124 to 123456?

Show Hint

Trace the closed loops the digits must travel through. The minimum number of swaps equals the digit count in each loop minus one, added up across all loops.
Updated On: Jul 15, 2026
  • 3
  • 4
  • 5
  • None of these
Show Solution

The Correct Option is A

Solution and Explanation

Since random switching allows swapping any two digits no matter how far apart they sit, this question is best answered with the standard loop counting rule for sorting by swaps, applied here in a slightly different order to the digits, followed by a fresh check sequence.

  1. Set up the rule: break the digits into closed loops by tracing, for each position, where its current digit needs to end up, and following that chain until it returns to the start. A sequence made of loops of sizes $k_1, k_2, \ldots$ can always be sorted in $(k_1 - 1) + (k_2 - 1) + \ldots$ swaps, and never fewer, when any two positions can be swapped.
  2. Trace the loops for 653124: position 3 already holds 3, its own correct value, so that is a loop of size 1 needing 0 swaps. Starting from position 2, it holds 5, whose correct home is position 5; position 5 holds 2, whose correct home is position 2. That closes a loop of size 2, needing 1 swap. The remaining positions 1, 4 and 6 hold 6, 1 and 4 respectively; 6 belongs at position 6, the digit at position 6 (4) belongs at position 4, and the digit at position 4 (1) belongs at position 1, closing a loop of size 3, needing 2 swaps.
  3. Add them up: $0 + 1 + 2 = 3$ swaps in total.
  4. Confirm with a different swap sequence: resolve the size 3 loop first by swapping positions 1 and 6 (values 6 and 4), turning 6 5 3 1 2 4 into 4 5 3 1 2 6, then swapping positions 1 and 4 (values 4 and 1), giving 1 5 3 4 2 6. Now resolve the size 2 loop by swapping positions 2 and 5 (values 5 and 2), giving 1 2 3 4 5 6. That is 3 swaps in total, using a different order of moves from a simulate-first approach, yet landing on the same result.

Let's summarize:

  • The digits split into loops of size 1, 2 and 3.
  • The fewest swaps for each loop is one less than its size, giving 0, 1 and 2, which add up to 3.

So the minimum number of random switch steps needed is 3, matching option (a).

Was this answer helpful?
0


Questions Asked in SNAP exam