Given an array, arr
which is a permutation of [0, 1, ..., arr.length - 1]
, we split the array into some number of "chunks" (partitions), and IND ividually sort each chunk. After concatenating them, the result equals the sorted array.
What's the most number of chunks we could have made?
Example 1:
Input:arr = [4,3,2,1,0]output:1explanation:splitting into, or more chunks would not return the required result. For example, splitting into [4, 3], [2, 1, 0] would result in [3, 4, 0, 1, 2], which isn ' t sorted.
Example 2:
Input:arr = [1,0,2,3,4]output:4explanation:we can split into and chunks, such as [1, 0], [2, 3, 4]. However, splitting to [1, 0], [2], [3], [4] is the highest number of chunks possible.
Note:
arr
Would has length in range [1, 10]
.
arr[i]
Would be a permutation of [0, 1, ..., arr.length - 1]
.
S
[Leetcode] Max Chunks to make Sorted sortable maximum block