title: Remove Minimum Elements Either Side 2Min Max
signature: class Solution {
  
      public int RemoveMinimumElementsEitherSide2MinMax(List<int> arr, int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{32, 50, 66, 73, 76, 87}, 5, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{68, 74, 16, 40, 6, -44, -36, 94, 6, -24, -4, -58, -16, 24}, 11, 
                  9
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 11, 
                  9
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{91, 22}, 1, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-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.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1}, 13, 
                  10
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-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.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 1, 1, 1, 1, 1, 1}, 6, 
                  2
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{25, 82}, 1, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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 ) );
  }