fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. // your code goes here
  9. int[] dayArr = {1,2,3,4,5,12,13,14,15,16,17,18,2,3,4,5 };
  10. List<int> days = new List<int>(dayArr);
  11. int longestSeqStart = days[0];
  12. int longestSeqEnd = days[0];
  13. int curSeqStart = days[0];
  14. int curSeqEnd = days[0];
  15. int lastVal = days[0];
  16. for(int i = 1; i < days.Count; i++)
  17. {
  18. if(days[i] == lastVal + 1)
  19. {
  20. curSeqEnd = days[i];
  21. if(curSeqEnd - curSeqStart > longestSeqEnd - longestSeqStart )
  22. {
  23. longestSeqStart = curSeqStart;
  24. longestSeqEnd = curSeqEnd;
  25. }
  26. }
  27. else
  28. {
  29. curSeqStart = curSeqEnd = days[i];
  30. }
  31. lastVal = days[i];
  32. }
  33.  
  34. Console.WriteLine(longestSeqStart + ", " + longestSeqEnd);
  35. }
  36. }
Success #stdin #stdout 0.03s 33848KB
stdin
Standard input is empty
stdout
1, 5