Skip to main content

LeetCode 3634. Minimum Removals to Balance Array in F#

Published 1 min readMarkdown

URL

Minimum Removals to Balance Array - LeetCode

Code

dotnet-study/fsharp/leetcode/challenge/202602/minimum_removals_to_balance_array/main.fsx at main · syohex/dotnet-study

let minRemoval (nums: int list) (k: int) : int =
    let k = int64 k

    let rec adjustWindow (nums: int64[]) left right : int =
        if left >= right then
            printfn "hige"
            left
        elif nums.[left] * k < nums.[right] then
            adjustWindow nums (left + 1) right
        else
            left

    let rec minRemoval' (nums: int64[]) left right acc =
        if right >= nums.Length then
            acc
        else
            let left = adjustWindow nums left right
            let acc = min acc (nums.Length - (right - left + 1))
            minRemoval' nums left (right + 1) acc

    let nums = nums |> List.map int64 |> List.sort |> List.toArray
    minRemoval' nums 0 0 System.Int32.MaxValue

No comments yet. Be the first to comment.