We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Minimum Distances
Minimum Distances
Sort by
recency
|
1362 Discussions
|
Please Login in order to post a comment
Java:
** Java 8 *
public static int minimumDistances(List a) { Map map = new HashMap<>(); int minDistance = 9999;
}
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; }
javascript Code O(n)
}