title: Minimum Difference Max Min K Size Subsets
signature: class Solution {
  
      public long MinimumDifferenceMaxMinKSizeSubsets(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, 4, 18, 21, 35, 37, 39, 76, 81, 86, 92, 96}, 7, 6, 
                  34
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-94, -86, -48, -48, -38, -8, -6, 0, 2, 24, 34, 52, 62}, 9, 12, 
                  2147483647
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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}, 16, 26, 
                  2147483647
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{3, 10, 13, 23, 30, 30, 34, 36, 37, 39, 43, 50, 57, 66, 71, 74, 81, 83, 89, 94, 94, 99}, 17, 20, 
                  2147483647
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-96, -94, -92, -84, -80, -72, -24, -22, -18, -14, 6, 8, 26, 28, 30, 36, 50, 58, 80, 84, 92, 92}, 21, 12, 
                  82
              );
              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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 22, 
                  2147483647
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{6, 7, 9, 27, 30, 42, 54, 55, 57, 57, 59, 76, 84, 84, 84}, 13, 14, 
                  2147483647
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-96, -86, -80, -72, -70, -68, -64, -64, -56, -54, -38, -30, -24, -16, -16, -12, -12, -10, 0, 0, 4, 4, 24, 28, 38, 40, 44, 48, 50, 54, 54, 62, 62, 68, 80, 84, 88, 88, 92, 94}, 31, 26, 
                  122
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 1}, 1, 1, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 6, 7, 8, 10, 10, 18, 54, 55, 56, 59, 59, 61, 63, 67, 69, 75, 78, 88, 89, 93, 97, 98}, 22, 14, 
                  39
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }