let max_run xs =
  let max_so_far = ref 0 in
  let cur = ref 0 in
  let last = ref None in
  List.iter (fun x ->
    (match !last with
     | Some y when y = x -> cur := !cur + 1
     | _ -> cur := 1);
    last := Some x;
    if !cur > !max_so_far then max_so_far := !cur
  ) xs;
  !max_so_far

;;

max_run [1;1;2;2;2;2;3;3;1;1;1] + max_run [1;2;3;4;5] + max_run []
