Hard · Sorting
Max Chunks to Make Sorted II
Given an integer array arr, split it into the largest number of contiguous chunks such that sorting each chunk on its own and concatenating the chunks gives arr in sorted order; return that number of chunks.
Examples
Example 1
[5,4,3,2,1]Output: 1 chunk
Example 2
[2,1,3,4,4]Output: 4 chunks
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.