LeetCode 1014. Best Sightseeing Pair in F#

URL

https://leetcode.com/problems/best-sightseeing-pair/description/?envType=daily-question&envId=2024-12-27

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202412/best_sightseeing_pair/main.fsx

let maxScoreSightseeingPair (values: int list) : int =
    let rec maxScoreSightseeingPair' values maxVal acc =
        match values with
        | [] -> acc
        | (i, n) :: t ->
            let sum = maxVal + n - i
            maxScoreSightseeingPair' t (max maxVal (n + i)) (max acc sum)

    match values |> List.indexed with
    | [] -> failwith "never reach here"
    | (_, h) :: t -> maxScoreSightseeingPair' t h 0