Hackerrank – Minimum Distances

Hackerrank – Problem Statement

A description of the problem can be found on Hackerrank.

Solution

Create index pairs variations for all indexes that pair are unique – it means when (i, j) exists (j, i) is the same. Filter only this pairs of indexes, which have the same value. Make an absolute difference of them |i-j| and choose the minimum value. if there are not differences, print -1.

I created solution in:

All solutions are also available on my GitHub.

Java

JavaScript

Scala

Ruby

Leave a Reply

Your email address will not be published. Required fields are marked *