You are viewing a single comment's thread. Return to all comments →
my approach with using c#
public static int minimumDistances(List a) { var unique = a.GroupBy(p => p).Where(o => o.Count() > 1).Select(o => o.Key).ToList(); List differences = new List(); foreach(var i in unique) { differences.Add(a.LastIndexOf(i) - a.IndexOf(i)); } return differences.Count() > 0 ? differences.Min() : -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Distances
You are viewing a single comment's thread. Return to all comments →
my approach with using c#
public static int minimumDistances(List a) { var unique = a.GroupBy(p => p).Where(o => o.Count() > 1).Select(o => o.Key).ToList(); List differences = new List(); foreach(var i in unique) { differences.Add(a.LastIndexOf(i) - a.IndexOf(i)); } return differences.Count() > 0 ? differences.Min() : -1; }