How to find most repeated words if any then return that word else return all words from array

I want to find most repeated words if any then return that word else return all words from array.

Input array:

{ABC , HTF, ABC, TF}

Output should be:
ABC

Input 2 array:
{AB, TC ,OP}
Output:
AB|TC|OP

Input 3:
{AB,TC,YU,AB,TC,UP,AB}
Output:
AB

Hi,

Can you try the following expression?

arrResult = arrInput.GroupBy(Function(s) s).GroupBy(Function(g) g.Count).OrderByDescending(Function(g) g.Key).First.Select(Function(g) g.Key).ToArray()

Note: arrResult and arrInput are String array.

Regards,

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.