Max Min Discussions | Algorithms | HackerRank
  • + 0 comments

    Java Solution

    Collections.sort(arr);
    int min=Integer.MAX_VALUE;
    for(int i=0;i<arr.size()-k+1;i++){
        if((arr.get(i+k-1)-arr.get(i))<min)
        {
            min=arr.get(i+k-1)-arr.get(i);
        }
    }
    return min;
    
    }