Not tested (written on the phone) but should do the trick
public static int GetDominator(IEnumerable<int> arr)
var num = arr.Count()/2;
return arr.GroupBy( x => x)
.Where(x => x.Count() > num)
.OrderByDesc(x => x.Count()) //in case there are more than one
.FirstOrDefault()? //pick the one most often or null, if there are none
.First() ?? -1;
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.