Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

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

Shohei Yoshida's photo
Shohei Yoshida
·Dec 27, 2022·

1 min read

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
 
Share this