LeetCode 2028. Find Missing Observations in F#

URL

Find Missing Observations - LeetCode

Code

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

let missingRolls (rolls: int list) (mean: int) (n: int) : int list =
    let rec missingRolls' n v m acc =
        if n = 0 then
            acc
        else if m > 0 then
            missingRolls' (n - 1) v (m - 1) ((v + 1) :: acc)
        else
            missingRolls' (n - 1) v 0 (v :: acc)

    let rollSum = List.sum rolls
    let sum = mean * (List.length rolls + n)
    let diff = sum - rollSum

    if diff < n || diff > 6 * n then
        []
    else
        let v = diff / n
        let m = diff % n
        missingRolls' n v m []