Skip to main content

LeetCode 3075. Maximize Happiness of Selected Children in F#

Published 1 min readMarkdown

URL

Maximize Happiness of Selected Children - LeetCode

Code

dotnet-study/fsharp/leetcode/challenge/202512/maxmize_happiness_of_selected_children/main.fsx at main · syohex/dotnet-study

let maximumHappinessSum (happiness: int list) (k: int) : int64 =
    happiness
    |> List.sort
    |> List.rev
    |> List.indexed
    |> List.take k
    |> List.fold (fun acc (i, v) -> acc + int64 (max (v - i) 0)) 0L

No comments yet. Be the first to comment.

More from this blog