Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

What is the minimum number of swaps of any two positions needed to make [2, 1, 2, 1, 3, 3, 1] sorted in non-decreasing order?

  1. A. 4
  2. B. 2
  3. C. 5
  4. D. 3

Correct answer: D. 3

Minimum swaps for a multiset arrangement is found by BFS over states, or by the mismatch-matrix count for two values. The adjacent-descent count is a different measure that over-counts for this array.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic