title: Remove Minimum Elements Either Side 2Min Max
signature: remove_minimum_elements_either_side_2min_max <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(32L, 50L, 66L, 73L, 76L, 87L), 5L, 
          1L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(68L, 74L, 16L, 40L, 6L, -44L, -36L, 94L, 6L, -24L, -4L, -58L, -16L, 24L), 11L, 
          9L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 11L, 
          9L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(91L, 22L), 1L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-84L, -80L, -78L, -76L, -58L, -54L, -52L, -48L, -42L, -42L, -40L, -38L, -34L, -32L, -28L, -24L, -6L, 2L, 2L, 4L, 10L, 14L, 16L, 18L, 26L, 26L, 36L, 40L, 50L, 52L, 62L, 64L, 72L, 74L, 84L, 90L, 94L, 96L, 98L), 35L, 
          28L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L), 13L, 
          10L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(10L, 19L, 25L, 29L, 32L, 37L, 40L, 43L, 43L, 44L, 46L, 51L, 51L, 54L, 56L, 58L, 63L, 79L, 83L, 86L, 87L, 97L, 97L), 11L, 
          2L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-48L, -28L, 10L, 30L, 78L, -72L, 78L, 52L, -52L, -68L, 56L, 42L, 8L, -42L, 16L, -56L, 2L, -90L, -26L, -28L, -56L, -2L, 80L, -50L, 98L, -64L, -96L, 10L, -10L, 44L, 98L, -48L, -88L, 42L, 30L, 24L, 38L, -26L, -52L, -12L, 0L, 34L, -82L, -80L, 0L, -84L, -20L), 25L, 
          23L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L), 6L, 
          2L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(25L, 82L), 1L, 
          0L
      )))
  
  }
  
  main()
source_py: def remove_minimum_elements_either_side_2min_max(arr, n):
      longest_start = (- 1)
      longest_end = 0
      for start in range(n):
          min = sys.maxsize
          max = (- sys.maxsize)
          for end in range(start, n):
              val = arr[end]
              if (val < min):
                  min = val
              if (val > max):
                  max = val
              if ((2 * min) <= max):
                  break
              if (((end - start) > (longest_end - longest_start)) or (longest_start == (- 1))):
                  longest_start = start
                  longest_end = end
      if (longest_start == (- 1)):
          return n
      return (n - ((longest_end - longest_start) + 1))
source_cpp: int remove_minimum_elements_either_side_2min_max(vector<int> arr, int n) {
    int longest_start = - 1, longest_end = 0;
    for ( int start = 0;
    start < n;
    start ++ ) {
      int min = INT_MAX, max = INT_MIN;
      for ( int end = start;
      end < n;
      end ++ ) {
        int val = arr [ end ];
        if ( val < min ) min = val;
        if ( val > max ) max = val;
        if ( 2 * min <= max ) break;
        if ( end - start > longest_end - longest_start || longest_start == - 1 ) {
          longest_start = start;
          longest_end = end;
        }
      }
    }
    if ( longest_start == - 1 ) return n;
    return ( n - ( longest_end - longest_start + 1 ) );
  }