I don’t know if my logic is correct or not. Can anyone please help me out, my solution was accepted but after reading this editorial. I found my solution nowhere close to the discussion.
So this is what I did.
I found the frequency of element which has occured the most, say sequence is (1,4,6,1,3,6). So max frequency is 2 be it for 6 or 1 doesn’t matter.
Since we have to find the minimum number of moves so I substract the max frequency from size of sequnce. In above case the size is 6. so minimum number of swappings is 6-2=4
Let’s take One of the given testcase 9 8 1 8
so max frequency is 2 (we are not bothered to find which element has max frequemcy, we just need max frequency) so length is 4
Can someone share there thoughts about this approach. It was accepted but still I’m confused if it’s right!