using System; using System.Collections.Generic; using System.Linq; using System.Globalization; public class Test { public static void Main() { int[] seq = new[] { 2, 1, 1, 2, 3, 3, 2, 2, 2, 1 }; int[] maxSeq = seq .Select((i, index) => new{ Item = i, index, PrevEqual = index == 0 || seq.ElementAt(index - 1) == i }) .Where(x => x.PrevEqual) .GroupBy(x => x.Item) .OrderByDescending(g => g.Count()) .First().Select(x => x.Item).ToArray(); Console.Write(string.Join(",", maxSeq.Select(i => i.ToString()).ToArray())); } }