title: Median Of Two Sorted Arrays
signature: median_of_two_sorted_arrays <- function(ar1, ar2, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      abs(actual - expected) < 1e-06
  }
  
  driver <- function(ar1, ar2, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(ar1, ar2, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 6L, 18L, 21L, 23L, 27L, 44L, 44L, 69L, 72L, 78L, 88L, 90L, 98L), list(6L, 12L, 16L, 18L, 26L, 34L, 48L, 48L, 49L, 56L, 61L, 79L, 81L, 89L), 12L, 
          39.0
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(90L, 54L, 24L, -10L, -84L, -74L, 58L, 96L, -28L, -92L, -18L, 90L, 70L, -60L, 72L, 78L, 10L, 42L, -2L, -18L, -38L, -16L, 18L, -86L, 40L, -46L, -38L, 66L, 20L, -16L, 48L), list(-72L, -62L, 14L, -58L, 70L, 54L, 88L, -40L, -94L, 4L, 60L, -16L, -38L, -98L, -70L, -46L, 66L, 42L, 26L, 36L, 56L, -4L, 32L, 30L, -46L, -42L, -72L, 44L, 16L, 4L, 24L), 16L, 
          22.0
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 1L, 1L), list(0L, 1L, 1L), 2L, 
          0.5
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(53L, 17L, 94L, 21L, 16L, 75L, 67L, 51L, 44L, 71L, 65L, 82L), list(98L, 50L, 8L, 11L, 80L, 41L, 59L, 24L, 94L, 41L, 75L, 78L), 10L, 
          84.5
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -92L, -80L, -68L, -64L, -64L, -60L, -56L, -52L, -50L, -50L, -22L, -20L, -4L, -2L, 0L, 6L, 20L, 22L, 28L, 38L, 40L, 48L, 50L, 56L, 58L, 64L, 64L, 80L, 82L, 90L, 92L, 92L, 92L), list(-88L, -72L, -72L, -58L, -54L, -50L, -48L, -34L, -24L, -14L, -14L, -14L, -10L, -6L, 4L, 12L, 16L, 18L, 26L, 30L, 32L, 34L, 40L, 46L, 52L, 54L, 58L, 62L, 62L, 72L, 82L, 82L, 92L, 98L), 25L, 
          -12.0
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L), list(1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L), 40L, 
          0.5
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(8L, 15L, 17L, 19L, 21L, 32L, 34L, 38L, 41L, 41L, 49L, 49L, 51L, 54L, 54L, 56L, 56L, 57L, 59L, 63L, 70L, 74L, 79L, 79L, 84L, 84L, 86L, 88L, 89L, 93L, 98L), list(5L, 6L, 17L, 18L, 22L, 29L, 32L, 33L, 36L, 44L, 45L, 47L, 59L, 59L, 60L, 65L, 67L, 68L, 69L, 71L, 72L, 76L, 78L, 81L, 84L, 85L, 85L, 86L, 86L, 87L, 92L), 29L, 
          56.5
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(96L, -42L, -94L, -46L, -68L, 76L, 8L, 16L, -54L, -94L, 76L, 24L, 94L, 10L, 34L, 78L, -30L, 0L, -52L, 80L, 98L, -58L, 92L, 12L, 26L, 64L), list(88L, 78L, -26L, 10L, 84L, 34L, 56L, -8L, -30L, 46L, 48L, 20L, 26L, -78L, 96L, 44L, 92L, -44L, -86L, 24L, -58L, -96L, -86L, -12L, -98L, 18L), 17L, 
          94.0
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 17L, 
          0.0
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(61L, 69L, 66L, 3L), list(39L, 84L, 97L, 15L), 3L, 
          67.5
      )))
  
  }
  
  main()
source_py: def median_of_two_sorted_arrays(ar1, ar2, n):
      i = 0
      j = 0
      m1 = (- 1)
      m2 = (- 1)
      count = 0
      while (count < (n + 1)):
          count += 1
          if (i == n):
              m1 = m2
              m2 = ar2[0]
              break
          elif (j == n):
              m1 = m2
              m2 = ar1[0]
              break
          if (ar1[i] < ar2[j]):
              m1 = m2
              m2 = ar1[i]
              i += 1
          else:
              m1 = m2
              m2 = ar2[j]
              j += 1
      return ((m1 + m2) / 2)
source_cpp: int median_of_two_sorted_arrays(vector<int> ar1, vector<int> ar2, int n) {
    int i = 0;
    int j = 0;
    int count;
    int m1 = - 1, m2 = - 1;
    for ( count = 0;
    count <= n;
    count ++ ) {
      if ( i == n ) {
        m1 = m2;
        m2 = ar2 [ 0 ];
        break;
      }
      else if ( j == n ) {
        m1 = m2;
        m2 = ar1 [ 0 ];
        break;
      }
      if ( ar1 [ i ] < ar2 [ j ] ) {
        m1 = m2;
        m2 = ar1 [ i ];
        i ++;
      }
      else {
        m1 = m2;
        m2 = ar2 [ j ];
        j ++;
      }
    }
    return ( m1 + m2 ) / 2;
  }