LeetCode 624. Maximum Distance in Arrays in F#
URL
Maximum Distance in Arrays - LeetCode
Code
let maxDistance (arrays: int list list) : int =
let rec maxDistance' arrays minVal maxVal ret =
match arrays with
| [] -> ret
| h :: t ->
let front, back = List.head h, List.last h
let ret = max ret (max (abs (maxVal - front)) (abs (back - minVal)))
maxDistance' t (min minVal front) (max maxVal back) ret
match arrays with
| [] -> failwith "never reach here"
| h :: t -> maxDistance' t (List.head h) (List.last h) 0