title: Minimum Length Subarray Sum Greater Given Value 1
signature: function minimumLengthSubarraySumGreaterGivenValue1(arr: Array<number>, n: number, x: number): number {
source_py: def minimum_length_subarray_sum_greater_given_value_1(arr, n, x):
      curr_sum = 0
      min_len = (n + 1)
      start = 0
      end = 0
      while (end < n):
          while ((curr_sum <= x) and (end < n)):
              if ((curr_sum <= 0) and (x > 0)):
                  start = end
                  curr_sum = 0
              curr_sum += arr[end]
              end += 1
          while ((curr_sum > x) and (start < n)):
              if ((end - start) < min_len):
                  min_len = (end - start)
              curr_sum -= arr[start]
              start += 1
      return min_len
source_cpp: int minimum_length_subarray_sum_greater_given_value_1(vector<int> arr, int n, int x) {
    int curr_sum = 0, min_len = n + 1;
    int start = 0, end = 0;
    while ( end < n ) {
      while ( curr_sum <= x && end < n ) {
        if ( curr_sum <= 0 && x > 0 ) {
          start = end;
          curr_sum = 0;
        }
        curr_sum += arr [ end ++ ];
      }
      while ( curr_sum > x && start < n ) {
        if ( end - start < min_len ) min_len = end - start;
        curr_sum -= arr [ start ++ ];
      }
    }
    return min_len;
  }
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"arr": [2, 4, 5, 10, 14, 15, 16, 20, 23, 28, 31, 35, 36, 36, 43, 48, 49, 55, 57, 57, 58, 61, 64, 64, 68, 70, 70, 73, 74, 76, 76, 77, 81, 81, 82, 87, 89, 92, 99], "n": 33, "x": 28}}, {"idx": 1, "outputs": 1, "inputs": {"arr": [66, -20, 12, -48, 22, 28, 40, -30, -6, -96, 10, -88, 40], "n": 11, "x": 12}}, {"idx": 2, "outputs": 43, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 42, "x": 23}}, {"idx": 3, "outputs": 1, "inputs": {"arr": [28, 19, 38, 31, 17, 27, 60, 35, 19, 47, 34, 51, 3, 95, 33, 29, 84, 46, 74, 87], "n": 15, "x": 15}}, {"idx": 4, "outputs": 2, "inputs": {"arr": [-48, -2], "n": 1, "x": 1}}, {"idx": 5, "outputs": 13, "inputs": {"arr": [1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1], "n": 12, "x": 15}}, {"idx": 6, "outputs": 1, "inputs": {"arr": [1, 4, 4, 6, 8, 10, 12, 12, 13, 15, 18, 20, 21, 23, 25, 28, 28, 33, 33, 35, 35, 36, 37, 38, 42, 44, 63, 63, 65, 65, 65, 66, 70, 74, 77, 78, 80, 80, 84, 87, 87, 89, 92, 93, 94, 97, 98, 99], "n": 42, "x": 27}}, {"idx": 7, "outputs": 1, "inputs": {"arr": [-82, -12, -40, 58, 22, -76, -94, -28, 42, 36, 64], "n": 10, "x": 6}}, {"idx": 8, "outputs": 11, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 10, "x": 14}}, {"idx": 9, "outputs": 1, "inputs": {"arr": [76, 65, 96, 76, 1, 91, 22, 29, 95, 21, 73, 68, 30, 52, 73, 86, 52, 66, 67, 37, 76, 53, 68, 6, 95, 81, 98, 42, 63, 38, 92, 78, 59, 86, 10, 38, 18, 15, 52, 62, 16, 66], "n": 23, "x": 35}}]
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, x: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver([2, 4, 5, 10, 14, 15, 16, 20, 23, 28, 31, 35, 36, 36, 43, 48, 49, 55, 57, 57, 58, 61, 64, 64, 68, 70, 70, 73, 74, 76, 76, 77, 81, 81, 82, 87, 89, 92, 99], 33, 28, 1);
    console.log(`TEST-0...${result}`);
  
    result = driver([66, -20, 12, -48, 22, 28, 40, -30, -6, -96, 10, -88, 40], 11, 12, 1);
    console.log(`TEST-1...${result}`);
  
    result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 42, 23, 43);
    console.log(`TEST-2...${result}`);
  
    result = driver([28, 19, 38, 31, 17, 27, 60, 35, 19, 47, 34, 51, 3, 95, 33, 29, 84, 46, 74, 87], 15, 15, 1);
    console.log(`TEST-3...${result}`);
  
    result = driver([-48, -2], 1, 1, 2);
    console.log(`TEST-4...${result}`);
  
    result = driver([1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1], 12, 15, 13);
    console.log(`TEST-5...${result}`);
  
    result = driver([1, 4, 4, 6, 8, 10, 12, 12, 13, 15, 18, 20, 21, 23, 25, 28, 28, 33, 33, 35, 35, 36, 37, 38, 42, 44, 63, 63, 65, 65, 65, 66, 70, 74, 77, 78, 80, 80, 84, 87, 87, 89, 92, 93, 94, 97, 98, 99], 42, 27, 1);
    console.log(`TEST-6...${result}`);
  
    result = driver([-82, -12, -40, 58, 22, -76, -94, -28, 42, 36, 64], 10, 6, 1);
    console.log(`TEST-7...${result}`);
  
    result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], 10, 14, 11);
    console.log(`TEST-8...${result}`);
  
    result = driver([76, 65, 96, 76, 1, 91, 22, 29, 95, 21, 73, 68, 30, 52, 73, 86, 52, 66, 67, 37, 76, 53, 68, 6, 95, 81, 98, 42, 63, 38, 92, 78, 59, 86, 10, 38, 18, 15, 52, 62, 16, 66], 23, 35, 1);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: minimumLengthSubarraySumGreaterGivenValue1
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