So if we give you a solution, it will mean that you failed.

Quote:Logic 1: count total number of consecutive pairs, and subtract it from the count of remainder elements. But it doesnt seem to work in all cases.

That mean that you have to refine your algorithm.

Find samples that don't work and search what changes to do to your algorithm.

Note that some samples can have no solution:

n = 4 a[] = {1, 1, 2, 1} answer = 0, no solution n = 5 a[] = {1, 1, 2, 1, 2} answer = 2 (swap a[1] with a[2] and a[3] with a[4] )

[Update]

Quote:Im not able to solve the question, and there is not much help online.

Try to device a brut force algorithm: try every possible swap and combinations of multiples swaps.