LeetCode 1561. Maximum Number of Coins You Can Get in F#

URL

Maximum Number of Coins You Can Get - LeetCode

Code

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

let maxCoins (piles: int list) : int =
    let rec maxCoins' tails acc =
        match tails with
        | [] -> acc
        | _ :: h :: t -> maxCoins' t (acc + h)
        | _ -> failwith "never reach here"

    let piles' = List.sort piles
    let len = List.length piles'
    let tails = List.skip (len / 3) piles' |> List.rev
    maxCoins' tails 0