This solution will only work if the majority element occurs more than half the size of the input array. Otherwise, your choice of using a map was great.
My code: public class MajorityElement { public static void main(String args[]){ int[] arr = {3,1,2,3,3,4}; int ans = majority(arr); System.out.println(ans); } static int majority(int[] arr){ int count =0; for(int i=0;i