let max_prod3 xs =
  let sorted = List.sort compare xs in
  let arr = Array.of_list sorted in
  let n = Array.length arr in
  let p1 = arr.(n - 1) * arr.(n - 2) * arr.(n - 3) in
  let p2 = arr.(0) * arr.(1) * arr.(n - 1) in
  if p1 > p2 then p1 else p2

;;

max_prod3 [-10; -10; 1; 3; 2]
