You are viewing a single comment's thread. Return to all comments →
Here is my c++ solution, you can watch the explanation here : https://youtu.be/H8aBskFE2XI
int minimumDistances(vector<int> a) { map<int, int>mp; int result = 1000; for(int i = 0; i < a.size(); i++){ if(mp[a[i]]){ result = min(result, i + 1 - mp[a[i]]); } mp[a[i]] = i+1; } return (result == 1000) ? -1:result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Distances
You are viewing a single comment's thread. Return to all comments →
Here is my c++ solution, you can watch the explanation here : https://youtu.be/H8aBskFE2XI