Max Chunks To Make Sorted - With Duplicates
Given a list of integers nums which may contain duplicates, your task is to divide the list into several partitions (chunks), sort each chunk individually, and then concatenate all chunks. The concatenated list should be sorted in ascending order.
Determine the maximum number of such partitions that can be created.
Input:
nums = [4, 3, 2, 1, 5]
Output:
1
Explanation:
Splitting into multiple chunks like [4, 3], [2, 1, 5] results in [3, 4, 1, 2, 5], which is not sorted.
Therefore, only one chunk (the entire array) works.
Input:
nums = [1, 2, 3, 4, 4]
Output:
5
Explanation:
Each element can be a chunk by itself, since sorting each single-element chunk and concatenating results in the sorted list.
Input:
nums = [2, 1, 3, 1, 4]
Output:
3
Explanation:
One possible partition is [2, 1], [3, 1], [4]. After sorting each chunk and concatenating, the final list is sorted.
nums is between 1 and 2500 inclusive.nums is an integer between 0 and 107 inclusive.