title: Minimize The Maximum Difference Between The Heights
signature: def minimize_the_maximum_difference_between_the_heights(arr, n, k):
source_py: def minimize_the_maximum_difference_between_the_heights(arr, n, k):
      if (n == 1):
          return 0
      arr.sort()
      ans = (arr[(n - 1)] - arr[0])
      small = (arr[0] + k)
      big = (arr[(n - 1)] - k)
      if (small > big):
          (small, big) = (big, small)
      for i in range(1, (n - 1)):
          subtract = (arr[i] - k)
          add = (arr[i] + k)
          if ((subtract >= small) or (add <= big)):
              continue
          if ((big - subtract) <= (add - small)):
              small = subtract
          else:
              big = add
      return min(ans, (big - small))
source_cpp: int minimize_the_maximum_difference_between_the_heights(vector<int> arr, int n, int k) {
    if ( n == 1 ) return 0;
    sort(arr.begin(), arr.end());
    int ans = arr [ n - 1 ] - arr [ 0 ];
    int small = arr [ 0 ] + k;
    int big = arr [ n - 1 ] - k;
    if ( small > big ) swap ( small, big );
    for ( int i = 1;
    i < n - 1;
    i ++ ) {
      int subtract = arr [ i ] - k;
      int add = arr [ i ] + k;
      if ( subtract >= small || add <= big ) continue;
      if ( big - subtract <= add - small ) small = subtract;
      else big = add;
    }
    return min ( ans, big - small );
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(arr, n, k, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              arr, n, k),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver([31, 33, 40, 43, 44, 51, 52, 56, 60, 64, 66, 79, 91, 93, 99], 10, 13, 19)
      print(f"TEST-0...{result}")
  
      result = driver([-86, -62, -16, 34, 54], 3, 4, 62)
      print(f"TEST-1...{result}")
  
      result = driver([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], 29, 22, 1)
      print(f"TEST-2...{result}")
  
      result = driver([3, 5, 5, 7, 9, 11, 16, 17, 21, 27, 36, 38, 41, 44, 45, 45, 48, 51, 55, 57, 58, 59, 59, 60, 67, 67, 67, 68, 70, 74, 77, 84, 86, 88, 90, 90, 91, 91, 92, 99], 28, 28, 52)
      print(f"TEST-3...{result}")
  
      result = driver([-88, -84, -78, -72, -66, -66, -58, -56, -56, -56, -54, -50, -50, -38, -24, -18, -12, -10, -8, -4, 0, 6, 8, 10, 14, 40, 44, 50, 58, 64, 64, 68], 22, 28, 44)
      print(f"TEST-4...{result}")
  
      result = driver([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], 10, 8, 1)
      print(f"TEST-5...{result}")
  
      result = driver([6, 11, 13, 14, 22, 25, 26, 28, 30, 31, 37, 37, 55, 57, 61, 62, 64, 67, 69, 70, 71, 73, 73, 75, 80, 81, 82, 88, 90, 98], 29, 26, 35)
      print(f"TEST-6...{result}")
  
      result = driver([-90, -86, -80, -78, -70, -64, -62, -38, -36, -32, -22, -18, -10, 4, 6, 20, 20, 24, 44, 52, 66, 82, 88, 92, 98], 23, 18, 142)
      print(f"TEST-7...{result}")
  
      result = driver([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], 20, 19, 1)
      print(f"TEST-8...{result}")
  
      result = driver([2], 0, 0, 0)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: minimize_the_maximum_difference_between_the_heights
question_info.test_list: [{"idx": 0, "outputs": 19, "inputs": {"arr": [31, 33, 40, 43, 44, 51, 52, 56, 60, 64, 66, 79, 91, 93, 99], "n": 10, "k": 13}}, {"idx": 1, "outputs": 62, "inputs": {"arr": [-86, -62, -16, 34, 54], "n": 3, "k": 4}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [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], "n": 29, "k": 22}}, {"idx": 3, "outputs": 52, "inputs": {"arr": [3, 5, 5, 7, 9, 11, 16, 17, 21, 27, 36, 38, 41, 44, 45, 45, 48, 51, 55, 57, 58, 59, 59, 60, 67, 67, 67, 68, 70, 74, 77, 84, 86, 88, 90, 90, 91, 91, 92, 99], "n": 28, "k": 28}}, {"idx": 4, "outputs": 44, "inputs": {"arr": [-88, -84, -78, -72, -66, -66, -58, -56, -56, -56, -54, -50, -50, -38, -24, -18, -12, -10, -8, -4, 0, 6, 8, 10, 14, 40, 44, 50, 58, 64, 64, 68], "n": 22, "k": 28}}, {"idx": 5, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], "n": 10, "k": 8}}, {"idx": 6, "outputs": 35, "inputs": {"arr": [6, 11, 13, 14, 22, 25, 26, 28, 30, 31, 37, 37, 55, 57, 61, 62, 64, 67, 69, 70, 71, 73, 73, 75, 80, 81, 82, 88, 90, 98], "n": 29, "k": 26}}, {"idx": 7, "outputs": 142, "inputs": {"arr": [-90, -86, -80, -78, -70, -64, -62, -38, -36, -32, -22, -18, -10, 4, 6, 20, 20, 24, 44, 52, 66, 82, 88, 92, 98], "n": 23, "k": 18}}, {"idx": 8, "outputs": 1, "inputs": {"arr": [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], "n": 20, "k": 19}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [2], "n": 0, "k": 0}}]
question_info.entry_cls_name: Solution