LeetCode 1823. Find the Winner of the Circular Game in F#

URL

Find the Winner of the Circular Game - LeetCode

Code

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

let findTheWinner (n: int) (k: int) : int =
    let rec findTheWinner' start k (v: int[]) =
        if Array.length v <= 1 then
            v.[0]
        else
            let removed = (start + k - 1) % (Array.length v)

            let v' =
                v |> Array.indexed |> Array.filter (fun (i, _) -> i <> removed) |> Array.map snd

            findTheWinner' removed k v'

    let v = Array.init n (fun i -> i + 1)
    findTheWinner' 0 k v