Find Majority element logic problem

Please tell me what is wrong with this code to find the majority elements in an array.

This code works in 1 case and was giving an error in other test cases.