LeetCode 2483. Minimum Penalty for a Shop in F#

URL

Minimum Penalty for a Shop - LeetCode

Code

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

let bestClosingTime (customers: string) : int =
    let rec bestClosingTime' i cs count min ret =
        match cs with
        | [] -> ret
        | h :: t ->
            let count' = if h = 'Y' then count - 1 else count + 1

            if count' < min then
                bestClosingTime' (i + 1) t count' count' i
            else
                bestClosingTime' (i + 1) t count' min ret

    let cs = Seq.toList customers
    let count = cs |> List.filter (fun c -> c = 'Y') |> List.length
    bestClosingTime' 1 cs count count 0