let count_chars s = let t = Hashtbl.create 8 in for i = 0 to String.length s - 1 do let c = s.[i] in let n = match Hashtbl.find_opt t c with | Some v -> v + 1 | None -> 1 in Hashtbl.replace t c n done; t let max_count t = Hashtbl.fold (fun _ v acc -> if v > acc then v else acc) t 0 ;; max_count (count_chars "abracadabra")