title: Minimum Difference Max Min K Size Subsets
signature: minimum_difference_max_min_k_size_subsets <- function(arr, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(1L, 1L, 4L, 18L, 21L, 35L, 37L, 39L, 76L, 81L, 86L, 92L, 96L), 7L, 6L, 
          34L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-94L, -86L, -48L, -48L, -38L, -8L, -6L, 0L, 2L, 24L, 34L, 52L, 62L), 9L, 12L, 
          2147483647L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 16L, 26L, 
          2147483647L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(3L, 10L, 13L, 23L, 30L, 30L, 34L, 36L, 37L, 39L, 43L, 50L, 57L, 66L, 71L, 74L, 81L, 83L, 89L, 94L, 94L, 99L), 17L, 20L, 
          2147483647L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -94L, -92L, -84L, -80L, -72L, -24L, -22L, -18L, -14L, 6L, 8L, 26L, 28L, 30L, 36L, 50L, 58L, 80L, 84L, 92L, 92L), 21L, 12L, 
          82L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 22L, 
          2147483647L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(6L, 7L, 9L, 27L, 30L, 42L, 54L, 55L, 57L, 57L, 59L, 76L, 84L, 84L, 84L), 13L, 14L, 
          2147483647L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-96L, -86L, -80L, -72L, -70L, -68L, -64L, -64L, -56L, -54L, -38L, -30L, -24L, -16L, -16L, -12L, -12L, -10L, 0L, 0L, 4L, 4L, 24L, 28L, 38L, 40L, 44L, 48L, 50L, 54L, 54L, 62L, 62L, 68L, 80L, 84L, 88L, 88L, 92L, 94L), 31L, 26L, 
          122L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 1L), 1L, 1L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(1L, 6L, 7L, 8L, 10L, 10L, 18L, 54L, 55L, 56L, 59L, 59L, 61L, 63L, 67L, 69L, 75L, 78L, 88L, 89L, 93L, 97L, 98L), 22L, 14L, 
          39L
      )))
  
  }
  
  main()
source_py: def minimum_difference_max_min_k_size_subsets(arr, N, K):
      arr.sort()
      res = 2147483647
      for i in range(((N - K) + 1)):
          curSeqDiff = (arr[((i + K) - 1)] - arr[i])
          res = min(res, curSeqDiff)
      return res
source_cpp: int minimum_difference_max_min_k_size_subsets(vector<int> arr, int N, int K) {
    sort(arr.begin(), arr.end());
    int res = INT_MAX;
    for ( int i = 0;
    i <= ( N - K );
    i ++ ) {
      int curSeqDiff = arr [ i + K - 1 ] - arr [ i ];
      res = min ( res, curSeqDiff );
    }
    return res;
  }