The Thomash algorithm will do the job with two calls to intersect and create intermediate lists, so it is not very efficient.
Your algorithm is essentially correct. The extra bit is that sometimes you have two heads equal to max, and you should leave only the remaining head.
Here is the edited algorithm written in OCaml:
let rec intersect xs ys zs = match xs, ys, zs with | [], _, _ | _, [], _ | _, _, [] -> None | x::xs', y::ys', z::zs' -> if x = y && y = z then Some x else let m = max x (max yz) in if x = m && y = m then intersect xs ys zs' else if x = m && z = m then intersect xs ys' zs else if y = m && z = m then intersect xs' ys zs else if x = m then intersect xs ys' zs' else if y = m then intersect xs' ys zs' else intersect xs' ys' zs
source share