LeetCode 1626. Best Team With No Conflicts in F#
URL
Best Team With No Conflicts - LeetCode
Code
https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/1626/main.fsx
let bestTeamScore (scores: int list) (ages: int list) : int =
let len = List.length scores
let ageScores = List.zip ages scores |> List.sort |> List.toArray
let dp =
ageScores
|> Array.indexed
|> Array.fold
(fun (acc: int[]) (i, (_, score)) ->
acc.[i] <- score
acc)
(Array.zeroCreate len)
let mutable ret = 0
for i in 0 .. (len - 1) do
for j in 0 .. (i - 1) do
if (snd ageScores.[i]) >= (snd ageScores.[j]) then
dp.[i] <- System.Math.Max(dp.[i], dp.[j] + (snd ageScores.[i]))
ret <- System.Math.Max(ret, dp.[i])
ret