LeetCode 2554. Maximum Number of Integers to Choose From a Range I in F#

URL

https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-i/description/?envType=daily-question&envId=2024-12-06

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202412/maximum_number_of_integers_to_choose_from_a_range1/main.fsx

let maxCount (banned: int list) (n: int) (maxSum: int) : int =
    let rec maxCount' i n count sum banned =
        if i > n then
            count
        else if Set.contains i banned then
            maxCount' (i + 1) n count sum banned
        else if i > sum then
            count
        else
            maxCount' (i + 1) n (count + 1) (sum - i) banned

    maxCount' 1 n 0 maxSum (Set.ofList banned)