LeetCode 2244. Minimum Rounds to Complete All Tasks in F#
URL
https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks/description/
Code
let minimumRounds (tasks: int list) : int =
let rec minimumRounds' values acc =
match values with
| [] -> acc
| h :: t ->
if h = 1 then
-1
else
minimumRounds'
t
(acc
+ (System.Math.Ceiling((double h) / 3.0) |> int))
let freq =
tasks
|> List.fold
(fun acc n ->
match Map.tryFind n acc with
| Some (v) -> Map.add n (v + 1) acc
| None -> Map.add n 1 acc)
Map.empty
minimumRounds' (Map.values freq |> Seq.toList) 0