LeetCode 1441. Build an Array With Stack Operations in F#

URL

https://leetcode.com/problems/build-an-array-with-stack-operations/description/

Code

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

let buildArray (target: int list) (n: int) : string list =
    target
    |> List.fold
        (fun (acc, i) num ->
            let diff = num - i - 1

            let acc' =
                seq { 0 .. (diff - 1) } |> Seq.fold (fun acc _ -> "Pop" :: "Push" :: acc) acc

            "Push" :: acc', i + 1 + diff)
        ([], 0)
    |> fst
    |> List.rev