LeetCode 1700. Number of Students Unable to Eat Lunch in F#

URL

https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/description/?envType=daily-question&envId=2024-04-08

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202404/number_of_students_unable_to_eat_lunch/main.fsx

let countStudents (students: int list) (sandwiches: int list) : int =
    let rec countStudents' sandwiches zeros ones =
        match sandwiches with
        | [] -> 0
        | h :: t ->
            if h = 0 && zeros > 0 then
                countStudents' t (zeros - 1) ones
            elif h = 1 && ones > 0 then
                countStudents' t zeros (ones - 1)
            else
                zeros + ones

    let zeros, ones =
        students
        |> List.fold (fun (zeros, ones) n -> if n = 0 then zeros + 1, ones else zeros, ones + 1) (0, 0)

    countStudents' sandwiches zeros ones