How to write an algorithm to find the shortest distance between two elements of an array in Swift

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.

--

--

--

Computer Engineer + iOS Engineer. I am interested in Swift, Kotlin, Firebase, Data Structures, ASO & On Solving Real World Problems.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Get a Better Development Experience on Your Mac

Bulbs in parallel

Introduction

SQL for Web Developers (Part I)

Running a Distributed Database on Kubernetes on Azure

Tips to maintain clean git commit history

Creaton Receives Investment from Tykhe Block Ventures to Build Web3 Creator Platform

Stunning VS-Code Themes……

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alcivanio (Swift)

Alcivanio (Swift)

Computer Engineer + iOS Engineer. I am interested in Swift, Kotlin, Firebase, Data Structures, ASO & On Solving Real World Problems.

More from Medium

10 Reasons Why Your iOS App Could be Rejected by Apple!

What is declarative and imperative way of programming in Swift?

My Top 5 WWDC 22 Moments

How Does Face ID or Touch ID Work? Intro to WebAuthn