URL
https://leetcode.com/problems/find-score-of-an-array-after-marking-all-elements/description/?envType=daily-question&envId=2024-12-13
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202412/find_score_of_an_array_after_making_all_elements/main.fsx
let findScore (nums: int list) : int64 =
nums
|> List.indexed
|> List.map (fun (i, n) -> int64 n, i)
|> List.sort
|> List.fold
(fun (acc, visited) (n, i) ->
if Set.contains i visited then
acc, visited
else
let visited = visited |> Set.add i |> Set.add (i - 1) |> Set.add (i + 1)
acc + n, visited)
(0L, Set.empty)
|> fst