Help with a code forces problem

problem link
Solution link
I have taken the range of every element that is if the difference is x then it lie in between x-2 to x+2, then i calculated the intersection of all difference range, then take an count and unordered map.
if the difference in this intersection then its frequency is increased otherwise count is increased, if size of map is greater then 2 than all other element have to be converted into an element so count+=mp.size()-1;
I dont kow what woring i am doing… all sample case passes but a test case give me a little bit different answer… please help…

Actually the problem isn’t asking for that much struggle. You can just check all possible situation and print the one which requires minimum change. As problem states only three operations are possible then in worse case you have to check 9 times. so it will be sill O(N) solution and work fine.

yes bro… , but i came up with this solution in virtual contest and i think it should give the right answer… . i dont know what wrong i am doing… i need to figure it out…