Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
For each (i, j) pair with i < j, test whether intervals (s1, e1)
and (s2, e2) overlap via the standard `s1 <= e2 && s2 <= e1`.
intervals: (1,4) (2,5) (7,9) (3,6) (8,10) (11,12) (0,2)
overlapping pairs:
(1,4) & (2,5) (1,4) & (3,6) (1,4) & (0,2)
(2,5) & (3,6) (2,5) & (0,2)
(7,9) & (8,10)
= 6
Tests double for-loop with both-side tuple destructure via
`let (s1, e1) = arr.(i) in`, conjunctive comparison, list-to-
array conversion.
188 baseline programs total.
17 lines
400 B
OCaml
17 lines
400 B
OCaml
let count_overlaps intervals =
|
|
let arr = Array.of_list intervals in
|
|
let n = Array.length arr in
|
|
let count = ref 0 in
|
|
for i = 0 to n - 1 do
|
|
let (s1, e1) = arr.(i) in
|
|
for j = i + 1 to n - 1 do
|
|
let (s2, e2) = arr.(j) in
|
|
if s1 <= e2 && s2 <= e1 then count := !count + 1
|
|
done
|
|
done;
|
|
!count
|
|
|
|
;;
|
|
|
|
count_overlaps [(1, 4); (2, 5); (7, 9); (3, 6); (8, 10); (11, 12); (0, 2)]
|