LeetCode 2275. Largest Combination With Bitwise AND Greater Than Zero in F#

URL

Largest Combination With Bitwise AND Greater Than Zero - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202411/largest_combination_with_bitwise_and_greater_than_zero/main.fsx

let largestCombination (candidates: int list) : int =
    seq { 0..31 }
    |> Seq.fold
        (fun (acc: int[]) i ->
            let bit = 1 <<< i

            candidates
            |> List.iter (fun cand ->
                if cand &&& bit <> 0 then
                    acc.[i] <- acc.[i] + 1)

            acc)
        (Array.zeroCreate 31)
    |> Array.max