ocaml: phase 5.1 min_subarr_target.ml baseline (min subarray sum >= 7 = 2)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Classic two-pointer / sliding window: expand right, then shrink
left while the window still satisfies the >= constraint, recording
the smallest valid length.
for r = 0 to n - 1 do
sum := !sum + arr.(r);
while !sum >= target do
... record (r - !l + 1) if smaller ...
sum := !sum - arr.(!l);
l := !l + 1
done
done
For [2; 3; 1; 2; 4; 3], target 7 -> window [4, 3] of length 2.
Sentinel n+1 marks "not found"; final guard reduces to 0.
Tests for + inner while shrinking loop, ref-tracked sum updated
on both expansion and contraction.
194 baseline programs total.
This commit is contained in:
@@ -125,6 +125,7 @@
|
||||
"merge_sort.ml": 44,
|
||||
"merge_two.ml": 441,
|
||||
"min_cost_path.ml": 12,
|
||||
"min_subarr_target.ml": 2,
|
||||
"module_use.ml": 3,
|
||||
"monotonic.ml": 4,
|
||||
"newton_sqrt.ml": 1414,
|
||||
|
||||
Reference in New Issue
Block a user