LeetCode 1331. Rank Transform of an Array in F#

URL

Rank Transform of an Array - LeetCode

Code

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

let arrayRankTransform (arr: int list) : int list =
    let m =
        arr
        |> List.countBy id
        |> List.map fst
        |> List.sort
        |> List.indexed
        |> List.fold (fun acc (i, n) -> Map.add n (i + 1) acc) Map.empty

    arr |> List.map (fun n -> Map.find n m)