title: Minimum Length Subarray Sum Greater Given Value
signature: function minimum_length_subarray_sum_greater_given_value(arr, n, x)
test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, x, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n, x) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({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)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-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)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 8, 12, 9)
      print(string.format("TEST-2...%s",result))
  
      result = driver({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)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-92, -68, -48, -48, -42, -26, -22, -18, 2, 4, 8, 14, 20, 22, 32, 46, 52, 62, 70, 96, 98}, 17, 14, 18)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0}, 11, 10, 12)
      print(string.format("TEST-5...%s",result))
  
      result = driver({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)
      print(string.format("TEST-6...%s",result))
  
      result = driver({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)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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)
      print(string.format("TEST-8...%s",result))
  
      result = driver({1, 33, 20, 32, 76, 27, 8, 95, 78, 72, 25, 56}, 9, 10, 1)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
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;
  }