fork(2) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5.  
  6. public class Test
  7. {
  8.  
  9. public static void Main()
  10. {
  11. int[] seq = new[] { 2, 1, 1, 2, 3, 3, 2, 2, 2, 1 };
  12. int[] maxSeq = seq
  13. .Select((i, index) => new{
  14. Item = i, index,
  15. PrevEqual = index == 0 || seq.ElementAt(index - 1) == i
  16. })
  17. .Where(x => x.PrevEqual)
  18. .GroupBy(x => x.Item)
  19. .OrderByDescending(g => g.Count())
  20. .First().Select(x => x.Item).ToArray();
  21.  
  22. Console.Write(string.Join(",", maxSeq.Select(i => i.ToString()).ToArray()));
  23. }
  24. }
Success #stdin #stdout 0.06s 37240KB
stdin
Standard input is empty
stdout
2,2,2