What is the quickest way of getting the most common item in a list or array?

I have looked into this using LINQ and using the O(n) algorithm to solve this problem however I can’t get anything to port to unity and work optimally for IOS. I was wondering if anyone has found a mobile performance friendly way of finding the most common item in a generic list or array.

Is there an optimal method using .js that compiles on IOS perhaps using sort/group by, or a way to use the for each loop which returns the most common vector3 in an array of vector3s? Any code examples would be much appreciated :slight_smile:

How about this one?

Dictionary<Item,int> dic
Item mostCommon = items[0]

for(int i = 1; i < items.Length; ++i)

dic[items*] += 1*
if(dic[items*] > dic[mostCommon])*
mostCommon = items

It just the first idea that came into my mind. Please share with me what do you think about it.