LeetCode 2966. Divide Array Into Arrays With Max Difference in F#

URL

Divide Array Into Arrays With Max Difference - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202401/divide_array_into_arrays_with_max_difference/main.fsx

let divideArray (nums: int list) (k: int) : (int * int * int) list =
    let rec divideArray' nums k acc =
        match nums with
        | [] -> List.rev acc
        | h1 :: h2 :: h3 :: t ->
            if h3 - h1 > k then
                []
            else
                divideArray' t k ((h1, h2, h3) :: acc)
        | _ -> failwith "never reach here"

    divideArray' (List.sort nums) k []