title: Print Maximum Shortest Distance
signature: function print_maximum_shortest_distance(a, n, k)
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(a, n, k, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(a, 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({2, 27, 66, 89, 96, 96}, 4, 4, 1000000000)
      print(string.format("TEST-0...%s",result))
  
      result = driver({84, -38, -56, -20, -98, -40, -16, 22, 20, 98, -56, -32, -44, 30, -58, 26, -44, -32, 50, 46, 92}, 13, 11, 1000000000)
      print(string.format("TEST-1...%s",result))
  
      result = driver({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}, 23, 13, 1000000000)
      print(string.format("TEST-2...%s",result))
  
      result = driver({20, 71, 66, 58, 74, 2, 63, 13, 1, 36, 28, 83, 24, 20, 85, 30, 59, 56, 8, 97, 58, 28, 28, 42}, 23, 17, 1000000000)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-94, -88, -86, -68, -66, -64, -28, -12, 4, 18, 22, 28, 32, 34, 34, 40, 44, 46, 60, 68, 72, 78, 80, 84, 88, 96}, 16, 15, 1000000000)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1}, 8, 13, 1000000000)
      print(string.format("TEST-5...%s",result))
  
      result = driver({8, 13, 54, 59, 61, 69, 89, 90, 92}, 4, 8, 1000000000)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-58, 50, -74, -8, -50, 90, 90, -2, -22, 8, -76, 16, 4, 56, 94, 36, 28, -42, 80, -88, 88, 52, 74, 40, 12, -72, -50, 50, 88, -54, 32, -24, -48, -66, -86, 40, -6, 14, 10, -88, 56, 80, -34}, 27, 42, 4)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 9, 12, 1000000000)
      print(string.format("TEST-8...%s",result))
  
      result = driver({2, 60, 66, 39, 18, 60, 37, 75, 3, 64, 24, 16, 72, 95, 96, 44, 23, 58, 58, 33, 24, 96}, 21, 17, 1000000000)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
source_py: def print_maximum_shortest_distance(a, n, k):
      b = dict()
      for i in range(n):
          x = a[i]
          d = min((1 + i), (n - i))
          if (x not in b.keys()):
              b[x] = d
          else:
              b[x] = min(d, b[x])
      ans = (10 ** 9)
      for i in range(n):
          x = a[i]
          if ((x != (k - x)) and ((k - x) in b.keys())):
              ans = min(max(b[x], b[(k - x)]), ans)
      return ans
source_cpp: int print_maximum_shortest_distance(vector<int> a, int n, int k) {
    unordered_map < int, int > b;
    for ( int i = 0;
    i < n;
    i ++ ) {
      int x = a [ i ];
      int d = min ( 1 + i, n - i );
      if ( b . find ( x ) == b . end ( ) ) b [ x ] = d;
      else b [ x ] = min ( d, b [ x ] );
    }
    int ans = INT_MAX;
    for ( int i = 0;
    i < n;
    i ++ ) {
      int x = a [ i ];
      if ( x != k - x && b . find ( k - x ) != b . end ( ) ) ans = min ( max ( b [ x ], b [ k - x ] ), ans );
    }
    return ans;
  }