fork(5) download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. int[] testArray = {1,5,6,8,9,4,4,6,3,2};
  9.  
  10. var adjacentDuplicate = testArray.Skip(1).Where((value,index) => value == testArray[index]).Distinct();
  11. Console.WriteLine ("Duplicates " + adjacentDuplicate.Select (x=>x.ToString()).Aggregate ((a,b) => a+ " " + b));
  12.  
  13. var adjacentIndex = testArray.Skip(1).Select((value,index) => value == testArray[index] ? index: 0).Where (x=> x!= 0);
  14. Console.WriteLine ("Index of duplicates " + adjacentIndex.Select (x=>x.ToString()).Aggregate ((a,b) => a+ " " + b));
  15.  
  16. }
  17. }
Success #stdin #stdout 0.05s 34016KB
stdin
Standard input is empty
stdout
Duplicates 4
Index of duplicates 5