When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

v0rtex's blog

By v0rtex, history, 2 years ago, In English

We are given an array of integers 1 <= a[i] <= 20, of size N (1<= N <= 10 ^ 5) and we have to group similar elements together. In one operation we can swap two adjacent elements. Find the minimum no of swaps.

Input — 1 2 1 2 1 Output — 3

Input — 1 3 3 2 Output — 0

Input — 1 3 2 1 2 3 Output — 4

Explanation of test case 3 — swap a[2] with a[3] swap a[4] with a[3] swap a[4] with a[5] swap a[2] with a[3] The array becomes — { 1, 1, 2, 2, 3, 3}

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

This Problem is the same with CF1215E Marbles.

Maybe you can go check out the editoral there.