Question: 
Write a function to extract maximum and minimum k elements in the given tuple.


Model's Code:
def extract_min_max(tup, k):
    if k <= 0 or k > len(tup):
        return ()
    sorted_tup = sorted(tup)
    return tuple(sorted_tup[:k] + sorted_tup[-k:])



Sample Correct Code:

def extract_min_max(test_tup, K):
  res = []
  test_tup = list(test_tup)
  temp = sorted(test_tup)
  for idx, val in enumerate(temp):
    if idx < K or idx >= len(temp) - K:
      res.append(val)
  res = tuple(res)
  return (res) 


Asserts:
assert extract_min_max((5, 20, 3, 7, 6, 8), 2) == (3, 5, 8, 20)
assert extract_min_max((4, 5, 6, 1, 2, 7), 3) == (1, 2, 4, 5, 6, 7)
assert extract_min_max((2, 3, 4, 8, 9, 11, 7), 4) == (2, 3, 4, 7, 8, 9, 11)


Tests:
Test 1 of 3: PASS
Test 2 of 3: PASS
Test 3 of 3: FAIL: AssertionError()

Test 219 of 974: 159/219 (72.6027397260274%): failed