LeetCode 2966. Divide Array Into Arrays With Max Difference in F#
URL
Divide Array Into Arrays With Max Difference - LeetCode
Code
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 []