title: Minimum Length Subarray Sum Greater Given Value 1
signature: minimum_length_subarray_sum_greater_given_value_1 <- function(arr, n, x) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, x, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, x), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 4L, 5L, 10L, 14L, 15L, 16L, 20L, 23L, 28L, 31L, 35L, 36L, 36L, 43L, 48L, 49L, 55L, 57L, 57L, 58L, 61L, 64L, 64L, 68L, 70L, 70L, 73L, 74L, 76L, 76L, 77L, 81L, 81L, 82L, 87L, 89L, 92L, 99L), 33L, 28L, 
          1L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(66L, -20L, 12L, -48L, 22L, 28L, 40L, -30L, -6L, -96L, 10L, -88L, 40L), 11L, 12L, 
          1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 42L, 23L, 
          43L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(28L, 19L, 38L, 31L, 17L, 27L, 60L, 35L, 19L, 47L, 34L, 51L, 3L, 95L, 33L, 29L, 84L, 46L, 74L, 87L), 15L, 15L, 
          1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-48L, -2L), 1L, 1L, 
          2L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L), 12L, 15L, 
          13L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(1L, 4L, 4L, 6L, 8L, 10L, 12L, 12L, 13L, 15L, 18L, 20L, 21L, 23L, 25L, 28L, 28L, 33L, 33L, 35L, 35L, 36L, 37L, 38L, 42L, 44L, 63L, 63L, 65L, 65L, 65L, 66L, 70L, 74L, 77L, 78L, 80L, 80L, 84L, 87L, 87L, 89L, 92L, 93L, 94L, 97L, 98L, 99L), 42L, 27L, 
          1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-82L, -12L, -40L, 58L, 22L, -76L, -94L, -28L, 42L, 36L, 64L), 10L, 6L, 
          1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 10L, 14L, 
          11L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(76L, 65L, 96L, 76L, 1L, 91L, 22L, 29L, 95L, 21L, 73L, 68L, 30L, 52L, 73L, 86L, 52L, 66L, 67L, 37L, 76L, 53L, 68L, 6L, 95L, 81L, 98L, 42L, 63L, 38L, 92L, 78L, 59L, 86L, 10L, 38L, 18L, 15L, 52L, 62L, 16L, 66L), 23L, 35L, 
          1L
      )))
  
  }
  
  main()
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;
  }