URL
https://leetcode.com/problems/max-chunks-to-make-sorted/description/?envType=daily-question&envId=2024-12-19
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202412/max_chunks_to_make_sorted/main.fsx
let maxChunksToSorted (arr: int list) : int =
let rec maxChunksToSorted' maxWindows right acc =
match maxWindows with
| [] -> acc
| (i, h) :: t ->
let right = max h right
let acc = if right <= i then acc + 1 else acc
maxChunksToSorted' t right acc
let maxWindows = arr |> List.indexed |> List.map (fun (i, n) -> i, max i n)
maxChunksToSorted' maxWindows 0 0