How to write an algorithm to find the shortest distance between two elements of an array in Swift
4 min readFeb 7, 2020
Today I was presented to this problem. Basically given a list of elements, I’d have to find the nearest distance between two elements of that list.
You can see an example of given list. Notice that we’re not talking about a set, which means that elements could possibly repeat.