Loading problem…
Split the permutation arr into nonempty contiguous chunks. Sort each chunk independently, then concatenate them in their original chunk order. Return the largest number of chunks whose concatenation is the fully sorted array.
arr contains every integer from 0 through arr.length - 1 exactly once. You choose boundaries, not arbitrary groups; elements cannot move between chunks.
Example 1:
Example 2:
Example 3: