LeetCode 3005. Count Elements With Maximum Frequency in F#

URL

https://leetcode.com/problems/count-elements-with-maximum-frequency/

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202403/count_elements_with_maximum_frequency/main.fsx

let maxFrequencyElements (nums: int list) : int =
    let max, freq =
        nums
        |> List.fold
            (fun (max, freq) n ->
                let v = Map.tryFind n freq |> Option.defaultValue 0
                System.Math.Max(max, v + 1), Map.add n (v + 1) freq)
            (0, Map.empty)

    freq |> Map.fold (fun acc _ v -> if v = max then acc + v else acc) 0