title: K Numbers Difference Maximum Minimum K Number Minimized
signature: function k_numbers_difference_maximum_minimum_k_number_minimized(arr, n, k)
test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, k, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n, k) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({1, 1, 2, 7, 8, 14, 16, 20, 20, 23, 24, 24, 29, 30, 32, 34, 35, 37, 38, 43, 44, 46, 50, 52, 55, 57, 61, 71, 79, 86, 86, 89, 91, 91, 95}, 33, 17, 32)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-80, -74, -70, -68, -66, -66, -62, -60, -60, -52, -50, -46, -34, -34, -28, -18, -4, 0, 6, 8, 16, 34, 34, 34, 42, 42, 44, 46, 54, 54, 54, 58, 62, 68, 72, 76, 78, 80, 84, 88, 90, 90}, 33, 33, 142)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 8, 13, 2147483647)
      print(string.format("TEST-2...%s",result))
  
      result = driver({32}, 0, 0, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-96, -78, -76, -72, -72, -70, -54, -46, -40, -34, -30, -26, -24, -22, -18, -16, -6, -4, -4, 2, 6, 14, 16, 18, 30, 30, 36, 54, 54, 58, 66, 72, 78, 80, 80, 82, 88, 98}, 26, 25, 108)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 39, 41, 2147483647)
      print(string.format("TEST-5...%s",result))
  
      result = driver({3, 13, 14, 18, 23, 32, 67, 72, 75, 76, 87, 95}, 10, 8, 62)
      print(string.format("TEST-6...%s",result))
  
      result = driver({8, 30}, 1, 1, 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 33, 2147483647)
      print(string.format("TEST-8...%s",result))
  
      result = driver({2, 3, 3, 7, 9, 15, 16, 19, 21, 25, 27, 29, 30, 31, 33, 35, 36, 36, 37, 40, 41, 42, 52, 52, 53, 57, 57, 63, 67, 67, 69, 72, 73, 74, 78, 83, 86, 87, 93, 94, 95, 95}, 36, 37, 2147483647)
      print(string.format("TEST-9...%s",result))
  
  end
  
  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;
  }