Find Majority Elements

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

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