title: Print Maximum Shortest Distance
signature: print_maximum_shortest_distance <- function(a, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 27L, 66L, 89L, 96L, 96L), 4L, 4L, 
          1000000000L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(84L, -38L, -56L, -20L, -98L, -40L, -16L, 22L, 20L, 98L, -56L, -32L, -44L, 30L, -58L, 26L, -44L, -32L, 50L, 46L, 92L), 13L, 11L, 
          1000000000L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 23L, 13L, 
          1000000000L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(20L, 71L, 66L, 58L, 74L, 2L, 63L, 13L, 1L, 36L, 28L, 83L, 24L, 20L, 85L, 30L, 59L, 56L, 8L, 97L, 58L, 28L, 28L, 42L), 23L, 17L, 
          1000000000L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-94L, -88L, -86L, -68L, -66L, -64L, -28L, -12L, 4L, 18L, 22L, 28L, 32L, 34L, 34L, 40L, 44L, 46L, 60L, 68L, 72L, 78L, 80L, 84L, 88L, 96L), 16L, 15L, 
          1000000000L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L), 8L, 13L, 
          1000000000L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(8L, 13L, 54L, 59L, 61L, 69L, 89L, 90L, 92L), 4L, 8L, 
          1000000000L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-58L, 50L, -74L, -8L, -50L, 90L, 90L, -2L, -22L, 8L, -76L, 16L, 4L, 56L, 94L, 36L, 28L, -42L, 80L, -88L, 88L, 52L, 74L, 40L, 12L, -72L, -50L, 50L, 88L, -54L, 32L, -24L, -48L, -66L, -86L, 40L, -6L, 14L, 10L, -88L, 56L, 80L, -34L), 27L, 42L, 
          4L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 9L, 12L, 
          1000000000L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(2L, 60L, 66L, 39L, 18L, 60L, 37L, 75L, 3L, 64L, 24L, 16L, 72L, 95L, 96L, 44L, 23L, 58L, 58L, 33L, 24L, 96L), 21L, 17L, 
          1000000000L
      )))
  
  }
  
  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;
  }