title: Remove Minimum Elements Either Side 2Min Max
signature: function removeMinimumElementsEitherSide2MinMax(arr: Array<number>, n: number): number {
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 ) );
  }
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"arr": [32, 50, 66, 73, 76, 87], "n": 5}}, {"idx": 1, "outputs": 9, "inputs": {"arr": [68, 74, 16, 40, 6, -44, -36, 94, 6, -24, -4, -58, -16, 24], "n": 11}}, {"idx": 2, "outputs": 9, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 11}}, {"idx": 3, "outputs": 0, "inputs": {"arr": [91, 22], "n": 1}}, {"idx": 4, "outputs": 28, "inputs": {"arr": [-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], "n": 35}}, {"idx": 5, "outputs": 10, "inputs": {"arr": [1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1], "n": 13}}, {"idx": 6, "outputs": 2, "inputs": {"arr": [10, 19, 25, 29, 32, 37, 40, 43, 43, 44, 46, 51, 51, 54, 56, 58, 63, 79, 83, 86, 87, 97, 97], "n": 11}}, {"idx": 7, "outputs": 23, "inputs": {"arr": [-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], "n": 25}}, {"idx": 8, "outputs": 2, "inputs": {"arr": [0, 0, 1, 1, 1, 1, 1, 1], "n": 6}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [25, 82], "n": 1}}]
question_info.entry_cls_name: Solution
question_info.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(arr: Array<number>, n: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver([32, 50, 66, 73, 76, 87], 5, 1);
    console.log(`TEST-0...${result}`);
  
    result = driver([68, 74, 16, 40, 6, -44, -36, 94, 6, -24, -4, -58, -16, 24], 11, 9);
    console.log(`TEST-1...${result}`);
  
    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);
    console.log(`TEST-2...${result}`);
  
    result = driver([91, 22], 1, 0);
    console.log(`TEST-3...${result}`);
  
    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);
    console.log(`TEST-4...${result}`);
  
    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);
    console.log(`TEST-5...${result}`);
  
    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);
    console.log(`TEST-6...${result}`);
  
    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);
    console.log(`TEST-7...${result}`);
  
    result = driver([0, 0, 1, 1, 1, 1, 1, 1], 6, 2);
    console.log(`TEST-8...${result}`);
  
    result = driver([25, 82], 1, 0);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: removeMinimumElementsEitherSide2MinMax
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js