title: Remove Minimum Elements Either Side 2Min Max
signature: int removeMinimumElementsEitherSide2MinMax(vector<int> arr, int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({32, 50, 66, 73, 76, 87}, 5, 1); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({68, 74, 16, 40, 6, -44, -36, 94, 6, -24, -4, -58, -16, 24}, 11, 9); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 11, 9); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({91, 22}, 1, 0); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-84, -80, -78, -76, -58, -54, -52, -48, -42, -42, -40, -38, -34, -32, -28, -24, -6, 2, 2, 4, 10, 14, 16, 18, 26, 26, 36, 40, 50, 52, 62, 64, 72, 74, 84, 90, 94, 96, 98}, 35, 28); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1}, 13, 10); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({10, 19, 25, 29, 32, 37, 40, 43, 43, 44, 46, 51, 51, 54, 56, 58, 63, 79, 83, 86, 87, 97, 97}, 11, 2); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-48, -28, 10, 30, 78, -72, 78, 52, -52, -68, 56, 42, 8, -42, 16, -56, 2, -90, -26, -28, -56, -2, 80, -50, 98, -64, -96, 10, -10, 44, 98, -48, -88, 42, 30, 24, 38, -26, -52, -12, 0, 34, -82, -80, 0, -84, -20}, 25, 23); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 1, 1, 1, 1, 1, 1}, 6, 2); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({25, 82}, 1, 0); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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 ) );
  }