Leet Code 2279. Maximum Bags With Full Capacity of Rocks in F#

URL

Maximum Bags With Full Capacity of Rocks - LeetCode

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/problems/2279/main.fsx

let maximumBags (capacity: int list) (rocks: int list) (additionalRocks: int) : int =
    let rec maximumBags' diffs additionalRocks acc =
        match diffs with
        | [] -> acc
        | h :: t ->
            if h <= additionalRocks then
                maximumBags' t (additionalRocks - h) (acc + 1)
            else
                acc

    let diffs = List.zip capacity rocks |> List.map (fun (a, b) -> a - b)
    maximumBags' diffs additionalRocks 0