code for finding the majority element in an array