Minimum Distances Hackerrank Solution