As reported: Rippling SDE 1 online assessment (Nov 2026), question 1 of 2.
This is LeetCode 768 — Max Chunks To Make Sorted II. Our write-up: /max-chunks-to-make-sorted-ii.
You are given an integer array arr; values may repeat. Split it into contiguous chunks, sort every chunk on its own, and concatenate the chunks in their original order. Return the largest number of chunks for which the result equals the fully sorted array.
Example 1
arr = [5,4,3,2,1]
Output: 1
Any split leaves a larger value in front of a smaller one, so the whole array must be one chunk.
Example 2
arr = [2,1,3,4,4]
Output: 4
[2,1] [3] [4] [4] works.
Constraints: 1 ≤ arr.length ≤ 2000; 0 ≤ arr[i] ≤ 10^8.
Code runner format: one JSON value per line: arr. Implement maxChunksToSorted(arr) and return the count.