LeetCode 2275. Largest Combination With Bitwise AND Greater Than Zero in F#
URL
Largest Combination With Bitwise AND Greater Than Zero - LeetCode
Code
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