title: Smallest Difference Pair Values Two Unsorted Arrays
signature: function smallestDifferencePairValuesTwoUnsortedArrays(a: Array<number>, b: Array<number>, m: number, n: number): number {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(a: Array<number>, b: Array<number>, m: number, n: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(a, b, m, n),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver([2, 2, 11, 13, 18, 18, 23, 25, 28, 28, 37, 39, 53, 56, 67, 70, 74, 74, 75, 79, 80, 82, 84, 89, 94, 95, 95, 98, 98], [5, 6, 11, 13, 13, 16, 17, 19, 23, 25, 28, 31, 31, 39, 41, 44, 45, 52, 62, 64, 70, 71, 73, 78, 78, 79, 85, 86, 92], 28, 14, 0);
    console.log(`TEST-0...${result}`);
  
    result = driver([-94, -78, -78, -72, -72, -72, -70, -70, -64, -62, -50, -48, -48, -44, -44, -40, -36, -36, -30, -24, -24, -22, -12, -10, -8, -4, -4, 0, 6, 10, 22, 30, 38, 56, 62, 72, 86], [-98, -98, -90, -84, -80, -78, -68, -62, -52, -50, -42, -30, -26, -24, -24, -24, -12, 2, 10, 14, 18, 22, 26, 26, 36, 42, 50, 60, 62, 64, 64, 72, 76, 78, 84, 86, 92], 23, 33, 0);
    console.log(`TEST-1...${result}`);
  
    result = driver([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], [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], 14, 16, 0);
    console.log(`TEST-2...${result}`);
  
    result = driver([2, 9, 15, 24, 28, 28, 39, 47, 57, 61, 71, 82, 90], [11, 26, 27, 41, 47, 49, 51, 54, 70, 77, 84, 85, 92], 7, 8, 1);
    console.log(`TEST-3...${result}`);
  
    result = driver([-92, -90, -90, -28, -16, -14, -14, -8, 42, 52, 62, 84], [-98, -98, -58, -6, 14, 16, 18, 46, 52, 52, 52, 56], 11, 6, 2);
    console.log(`TEST-4...${result}`);
  
    result = driver([0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1], 35, 33, 0);
    console.log(`TEST-5...${result}`);
  
    result = driver([6, 7, 7, 12, 15, 15, 21, 24, 26, 26, 28, 36, 38, 42, 46, 52, 55, 56, 59, 62, 63, 65, 65, 66, 68, 71, 73, 77, 77, 77, 77, 85, 87, 87, 88, 90, 93, 94, 98], [1, 3, 4, 4, 6, 7, 8, 8, 15, 17, 18, 18, 20, 23, 23, 24, 25, 25, 26, 33, 39, 43, 46, 54, 59, 67, 69, 69, 69, 69, 76, 76, 81, 81, 85, 86, 86, 91, 95], 30, 20, 0);
    console.log(`TEST-6...${result}`);
  
    result = driver([-82, -68, -68, -60, -60, -38, -20, -16, 4, 18, 18, 22, 24, 30, 34, 44, 70, 78, 88, 90, 94], [-74, -68, -64, -62, -60, -52, -50, -44, -36, -34, -32, -30, -20, -18, -14, -2, 18, 62, 62, 84, 98], 16, 12, 0);
    console.log(`TEST-7...${result}`);
  
    result = driver([0, 0, 1], [0, 0, 1], 2, 1, 0);
    console.log(`TEST-8...${result}`);
  
    result = driver([2, 7, 7, 9, 14, 15, 16, 20, 21, 26, 35, 37, 40, 45, 46, 47, 53, 56, 58, 61, 62, 67, 70, 70, 71, 73, 81, 85, 85, 90, 94, 98, 99], [1, 7, 14, 16, 18, 19, 24, 27, 28, 29, 29, 37, 41, 44, 45, 48, 49, 55, 64, 67, 67, 71, 72, 79, 80, 84, 86, 88, 88, 92, 94, 98, 99], 20, 25, 0);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
source_py: def smallest_difference_pair_values_two_unsorted_arrays(A, B, m, n):
      A.sort()
      B.sort()
      a = 0
      b = 0
      result = sys.maxsize
      while ((a < m) and (b < n)):
          if (abs((A[a] - B[b])) < result):
              result = abs((A[a] - B[b]))
          if (A[a] < B[b]):
              a += 1
          else:
              b += 1
      return result
source_cpp: int smallest_difference_pair_values_two_unsorted_arrays(vector<int> A, vector<int> B, int m, int n) {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int a = 0, b = 0;
    int result = INT_MAX;
    while ( a < m && b < n ) {
      if ( abs ( A [ a ] - B [ b ] ) < result ) result = abs ( A [ a ] - B [ b ] );
      if ( A [ a ] < B [ b ] ) a ++;
      else b ++;
    }
    return result;
  }