Skip to main content

LeetCode 2300. Successful Pairs of Spells and Potions in F#

Published 1 min readMarkdown

URL

Successful Pairs of Spells and Potions - LeetCode

Code

dotnet-study/fsharp/leetcode/challenge/202510/successful_pairs_of_spells_and_potions/main.fsx at master · syohex/dotnet-study

let successfulPairs (spells: int list) (potions: int list) (success: int64) : int list =
    let rec lowerBound left right spell (vals: int[]) =
        if left >= right then
            left
        else
            let mid = left + (right - left) / 2

            if int64 (spell * vals.[mid]) < success then
                lowerBound (mid + 1) right spell vals
            else
                lowerBound left mid spell vals

    let potions = potions |> List.sort |> List.toArray
    let len = potions.Length

    spells
    |> List.map (fun spell ->
        let pos = lowerBound 0 len spell potions
        len - pos)

No comments yet. Be the first to comment.

More from this blog