LeetCode 1331. Rank Transform of an Array in F#
URL
Rank Transform of an Array - LeetCode
Code
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)