Skip to content

Instantly share code, notes, and snippets.

@samarthsewlani
Created February 22, 2021 08:25
Show Gist options
  • Save samarthsewlani/0fb0a15f6464253fdaceec8c1a075bbc to your computer and use it in GitHub Desktop.
Save samarthsewlani/0fb0a15f6464253fdaceec8c1a075bbc to your computer and use it in GitHub Desktop.
Minimum Distances HackerRank Solution ( Brute Force )
def minimumDistances(a):
n=len(a)
minimum=n+1 #Initializing with n+1 because if no updates take place we should return -1 as there are no matching pairs
# Note:- If any matching pairs is found the distance would be less than n
for i in range(n-1):
for j in range(i+1,n):
if a[i]==a[j]:
if j-i<minimum:
minimum=j-i
if minimum==n+1:
return -1
return minimum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment