title: Minimum Difference Max Min K Size Subsets
signature: function minimum_difference_max_min_k_size_subsets(arr, n, k)
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;
  }
question_info.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, 4, 18, 21, 35, 37, 39, 76, 81, 86, 92, 96}, 7, 6, 34)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-94, -86, -48, -48, -38, -8, -6, 0, 2, 24, 34, 52, 62}, 9, 12, 2147483647)
      print(string.format("TEST-1...%s",result))
  
      result = driver({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)
      print(string.format("TEST-2...%s",result))
  
      result = driver({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)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-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)
      print(string.format("TEST-4...%s",result))
  
      result = driver({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)
      print(string.format("TEST-5...%s",result))
  
      result = driver({6, 7, 9, 27, 30, 42, 54, 55, 57, 57, 59, 76, 84, 84, 84}, 13, 14, 2147483647)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-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)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 1}, 1, 1, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({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)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 34, "inputs": {"arr": [1, 1, 4, 18, 21, 35, 37, 39, 76, 81, 86, 92, 96], "n": 7, "k": 6}}, {"idx": 1, "outputs": 2147483647, "inputs": {"arr": [-94, -86, -48, -48, -38, -8, -6, 0, 2, 24, 34, 52, 62], "n": 9, "k": 12}}, {"idx": 2, "outputs": 2147483647, "inputs": {"arr": [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], "n": 16, "k": 26}}, {"idx": 3, "outputs": 2147483647, "inputs": {"arr": [3, 10, 13, 23, 30, 30, 34, 36, 37, 39, 43, 50, 57, 66, 71, 74, 81, 83, 89, 94, 94, 99], "n": 17, "k": 20}}, {"idx": 4, "outputs": 82, "inputs": {"arr": [-96, -94, -92, -84, -80, -72, -24, -22, -18, -14, 6, 8, 26, 28, 30, 36, 50, 58, 80, 84, 92, 92], "n": 21, "k": 12}}, {"idx": 5, "outputs": 2147483647, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 21, "k": 22}}, {"idx": 6, "outputs": 2147483647, "inputs": {"arr": [6, 7, 9, 27, 30, 42, 54, 55, 57, 57, 59, 76, 84, 84, 84], "n": 13, "k": 14}}, {"idx": 7, "outputs": 122, "inputs": {"arr": [-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], "n": 31, "k": 26}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [0, 1], "n": 1, "k": 1}}, {"idx": 9, "outputs": 39, "inputs": {"arr": [1, 6, 7, 8, 10, 10, 18, 54, 55, 56, 59, 59, 61, 63, 67, 69, 75, 78, 88, 89, 93, 97, 98], "n": 22, "k": 14}}]
question_info.extension: lua
question_info.entry_fn_name: minimum_difference_max_min_k_size_subsets
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__