Max Min Discussions | Algorithms | HackerRank
  • + 0 comments

    `java public static int maxMin(int k, List arr) { // Write your code here // Sorting and Sliding Window Collections.sort(arr); int min = 0; int end = 0; int start = 0; int minUnfairness = Integer.MAX_VALUE; while(end < arr.size()) { if((end-start)+1 < k) { end++; }else { int currentUnfairness = arr.get(end) - arr.get(start); minUnfairness = Math.min(minUnfairness, currentUnfairness); start++; } } return minUnfairness; }

    `