using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
namespace ConsoleApplication9
public static void Main()
Stopwatch timer = Stopwatch.StartNew();
Console.WriteLine("Orignal: " + timer.ElapsedTicks);
timer = Stopwatch.StartNew();
Console.WriteLine("Tommy: " + timer.ElapsedTicks);
timer = Stopwatch.StartNew();
Console.WriteLine("Berkser: " + timer.ElapsedTicks);
timer = Stopwatch.StartNew();
Console.WriteLine("Hari: " + timer.ElapsedTicks);
timer = Stopwatch.StartNew();
Console.WriteLine("user3185569: " + timer.ElapsedTicks);
public static void Original()
int[] arr = new int[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4 };
var countlist = arr.Aggregate(new Dictionary<int, int>(), (D, i) => {
D[i] = D.ContainsKey(i) ? (D[i] + 1) : 1;
.OrderByDescending(x => x.Value)
Console.WriteLine(countlist[3]);
public static void berkser()
int[] arr = new int[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4 };
var result = arr.GroupBy(x => x)
.Select(x => new { Item = x.Key, Count = x.Count() })
Console.WriteLine(result.ElementAt(2).Item);
public static void Tommy()
int[] arr = new int[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4 };
var lookup = arr.ToLookup(t => t);
var result = lookup.OrderByDescending(t => t.Count());
Console.WriteLine(result.ElementAt(1).Key);
public static void Hari()
int[] arr = new int[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4 };
var item = arr.GroupBy(x => x)
.OrderByDescending(x => x.Count())
Console.WriteLine(item.Key);
public static void user3185569()
int[] arr = new int[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4 };
private static int? NthElement4(int[] array, int n)
int[] holdingResults = new int[array.Max()];
int? currentMax = new int?();
for (int i = 0; i < n; i++)
for (int j = 0; j < holdingResults.Length; j++)
int currentItem = holdingResults[j];
if (currentItem > localMax && (!currentMax.HasValue || currentItem < currentMax))
if (localMax < currentMax || !currentMax.HasValue)
currentMaxIndex = localMaxIndex;
return currentMaxIndex + 1;