Sort by

recency

|

1399 Discussions

|

  • + 0 comments

    //my very simple cpp solutuions//

    int minimumDistances(vector a) {

    vector<int>b;
    bool flag =1;
    
    for(int i = 0;i < a.size();i++){
        { int count;
            for(int j=i+1;j < a.size();j++){
                if(a[i] ==a[j]){
                    count=abs(j - i);
                     flag=0;
                }
            }b.push_back(count);
        }
    }
    if(flag == 1){
        return -1;
    }
    
    int min=b[0];
    for(int i = 0;i < b.size();i++){
        if(b[i] < min){
            min=b[i];
        }
    }
    
    return min;
    

    }

  • + 0 comments
    def minimumDistances(a):
        min_distance = length = len(a)
        d = dict()
        for index, el in enumerate(a):
            distance = abs(index - d.setdefault(el, index))
            if distance:
                min_distance = min(distance, min_distance)
    
        if length == min_distance:
            return -1
        return min_distance
    
  • + 0 comments
    public static int minimumDistances(List<Integer> arr) {
        Map<Integer, LinkedList<Integer>> itemDistanceMap = new HashMap<>();
        for(int i=0;i<arr.size(); i++) {
            int key = arr.get(i);
            if(itemDistanceMap.get(key) == null) {
                LinkedList<Integer> indices = new LinkedList<>();
                indices.add(i);
                itemDistanceMap.put(key, indices);
            } else {
                itemDistanceMap.get(key).add(i);
            }
        }
    
        int minDistance = Integer.MAX_VALUE;
    
        Collection<LinkedList<Integer>> distances = itemDistanceMap.values();
    
        for(LinkedList<Integer> distanceLst : distances) {
            if(distanceLst.size() > 1) {
                int distance = distanceLst.get(1) - distanceLst.get(0);
                minDistance = distance < minDistance ? distance : minDistance;
            }
        }        
        return minDistance == Integer.MAX_VALUE ? -1 : minDistance;
    }
    
  • + 0 comments

    If you're around Delano and need banners printed, there's a place that understands how important quality and timing are. Minimum distance doesn’t have to mean sacrificing impact—Banners Printing in Delano makes it easy to create bold, clear, and professional displays without going far. Whether it’s for an event, promotion, or celebration, you can count on friendly service and crisp results. No need to stress about long drives or complicated orders. Everything you need is just around the corner. The process is smooth, and the team is always ready to help bring your ideas to life. Banners Printing in Delano is the easy choice when you need it done right, close to home.

  • + 0 comments

    Here is problem solution in Python Java C++ C and Javascript - https://programmingoneonone.com/hackerrank-minimum-distance-problem-solution.html