title: Minimum Length Subarray Sum Greater Given Value
signature: func minimumLengthSubarraySumGreaterGivenValue(arr []int, n int, x int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, n int, x int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, n, x),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{6, 11, 11, 14, 18, 19, 21, 22, 22, 23, 26, 27, 28, 28, 29, 30, 31, 34, 39, 42, 42, 44, 45, 49, 49, 53, 57, 61, 65, 66, 67, 70, 71, 73, 74, 74, 78, 85, 88, 94, 95, 97}, 
  	37, 
  	23, 1)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{-30, -22, -66, -80, 18, -64, -28, -46, 94, 60, -64, 2, 26, -94, 58, 56, 56, 88, 50, -78, -12, 68, 54, -78, 42, -30, 24, -48, 84, 12, -88, 0, 54, -92, -4, 42, -60, -72, -32}, 
  	31, 
  	29, 1)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	8, 
  	12, 9)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{86, 8, 23, 40, 55, 93, 11, 35, 33, 37, 96, 91, 35, 66, 37, 57, 83, 99, 96, 15, 18, 93}, 
  	16, 
  	13, 1)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-92, -68, -48, -48, -42, -26, -22, -18, 2, 4, 8, 14, 20, 22, 32, 46, 52, 62, 70, 96, 98}, 
  	17, 
  	14, 18)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0}, 
  	11, 
  	10, 12)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{4, 4, 11, 11, 13, 15, 16, 18, 19, 19, 19, 23, 26, 27, 34, 39, 39, 40, 41, 46, 47, 51, 52, 52, 53, 57, 58, 58, 60, 64, 68, 70, 72, 84, 84, 85, 95, 98, 99}, 
  	31, 
  	35, 1)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{12, -22, 2, -90, -92, 84, -26, -76, -72, 50, -36, 30, 78, -18, -94, -30, 22, 28, 10, 32, 34, -86, 0, -4, 40, 0, 80, 50, 66, -48, -40, -94, 64, 58, -14, 0, -32, -58, -22, -94, -68, -36, -94, -48, 40, 78, -74}, 
  	42, 
  	26, 43)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{0, 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}, 
  	25, 
  	21, 26)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{1, 33, 20, 32, 76, 27, 8, 95, 78, 72, 25, 56}, 
  	9, 
  	10, 1)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def minimum_length_subarray_sum_greater_given_value(arr, n, x):
      curr_sum = 0
      min_len = (n + 1)
      start = 0
      end = 0
      while (end < n):
          while ((curr_sum <= x) and (end < n)):
              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(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 ) 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;
  }