title: K Numbers Difference Maximum Minimum K Number Minimized
signature: class Solution {
  
      public long KNumbersDifferenceMaximumMinimumKNumberMinimized(List<int> arr, int n, int k) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(long actual, long expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int k, long expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                long pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n, k); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-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
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 8, 13, 
                  2147483647
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{32}, 0, 0, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-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
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{3, 13, 14, 18, 23, 32, 67, 72, 75, 76, 87, 95}, 10, 8, 
                  62
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{8, 30}, 1, 1, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }