title: K Numbers Difference Maximum Minimum K Number Minimized
signature: k_numbers_difference_maximum_minimum_k_number_minimized <- 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, 2L, 7L, 8L, 14L, 16L, 20L, 20L, 23L, 24L, 24L, 29L, 30L, 32L, 34L, 35L, 37L, 38L, 43L, 44L, 46L, 50L, 52L, 55L, 57L, 61L, 71L, 79L, 86L, 86L, 89L, 91L, 91L, 95L), 33L, 17L, 
          32L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-80L, -74L, -70L, -68L, -66L, -66L, -62L, -60L, -60L, -52L, -50L, -46L, -34L, -34L, -28L, -18L, -4L, 0L, 6L, 8L, 16L, 34L, 34L, 34L, 42L, 42L, 44L, 46L, 54L, 54L, 54L, 58L, 62L, 68L, 72L, 76L, 78L, 80L, 84L, 88L, 90L, 90L), 33L, 33L, 
          142L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L), 8L, 13L, 
          2147483647L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(32L), 0L, 0L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -78L, -76L, -72L, -72L, -70L, -54L, -46L, -40L, -34L, -30L, -26L, -24L, -22L, -18L, -16L, -6L, -4L, -4L, 2L, 6L, 14L, 16L, 18L, 30L, 30L, 36L, 54L, 54L, 58L, 66L, 72L, 78L, 80L, 80L, 82L, 88L, 98L), 26L, 25L, 
          108L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 39L, 41L, 
          2147483647L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 13L, 14L, 18L, 23L, 32L, 67L, 72L, 75L, 76L, 87L, 95L), 10L, 8L, 
          62L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(8L, 30L), 1L, 1L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 27L, 33L, 
          2147483647L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(2L, 3L, 3L, 7L, 9L, 15L, 16L, 19L, 21L, 25L, 27L, 29L, 30L, 31L, 33L, 35L, 36L, 36L, 37L, 40L, 41L, 42L, 52L, 52L, 53L, 57L, 57L, 63L, 67L, 67L, 69L, 72L, 73L, 74L, 78L, 83L, 86L, 87L, 93L, 94L, 95L, 95L), 36L, 37L, 
          2147483647L
      )))
  
  }
  
  main()
source_py: def k_numbers_difference_maximum_minimum_k_number_minimized(arr, n, k):
      result = (+ 2147483647)
      arr.sort()
      for i in range(((n - k) + 1)):
          result = int(min(result, (arr[((i + k) - 1)] - arr[i])))
      return result
source_cpp: int k_numbers_difference_maximum_minimum_k_number_minimized(vector<int> arr, int n, int k) {
    int result = INT_MAX;
    sort(arr.begin(), arr.end());
    for ( int i = 0;
    i <= n - k;
    i ++ ) result = min ( result, arr [ i + k - 1 ] - arr [ i ] );
    return result;
  }