function to compute majority in an array in linear time implemented