let min_subarr_sum_at_least arr target =
  let n = Array.length arr in
  let best = ref (n + 1) in
  let sum = ref 0 in
  let l = ref 0 in
  for r = 0 to n - 1 do
    sum := !sum + arr.(r);
    while !sum >= target do
      let len = r - !l + 1 in
      if len < !best then best := len;
      sum := !sum - arr.(!l);
      l := !l + 1
    done
  done;
  if !best > n then 0 else !best

;;

min_subarr_sum_at_least [| 2; 3; 1; 2; 4; 3 |] 7
