Skip to main content
LeetCode 768, Hard. Topics: Array, Stack, Greedy, Sorting, Monotonic Stack. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 24 parametrized pytest cases, and a playground notebook:

Problem

You are given an integer array arr. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array. Return the largest number of chunks we can make to sort the array.

Examples

Constraints

  • 1 <= arr.length <= 2000
  • 0 <= arr[i] <= 10^8

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026