score:1

Accepted answer

this should work fine

var topthreemostoccuring = arr.groupby(x => x)
.orderbydescending(g => g.count())
.selectmany(x => x.take(1)).take(3);

score:0

hope this helps you

 var list = new list<int>();

        list.add(5);
        list.add(5);
        list.add(27);
        list.add(4);
        list.add(3);
        list.add(4);
        list.add(4);
        list.add(29);
        list.add(3);
        list.add(5);
        list.add(4);



       var themostoccurring =  list.groupby(n => n).orderbydescending(m => m.count()).select(m => m.key).tolist().take(3);



        foreach (var item in themostoccurring)
        {
            console.writeline(item);
        }

score:1

you can use linq :

var top3 = list.groupby(x => x)
               .orderbydescending(x => x.count())
               .take(3)
               .select(x => x.key);

console.writeline(string.join(" ", top3)); // output 5 3 4

Related Query

More Query from same tag