769. Max Chunks To Make Sorted Medium

@problem@discussion
#Array#Stack#Greedy#Sorting#Monotonic Stack



1/**
2 * [769] Max Chunks To Make Sorted
3 *
4 * You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1].
5 * 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.
6 * Return the largest number of chunks we can make to sort the array.
7 *  
8 * Example 1:
9 * 
10 * Input: arr = [4,3,2,1,0]
11 * Output: 1
12 * Explanation:
13 * Splitting into two or more chunks will not return the required result.
14 * For example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.
15 * 
16 * Example 2:
17 * 
18 * Input: arr = [1,0,2,3,4]
19 * Output: 4
20 * Explanation:
21 * We can split into two chunks, such as [1, 0], [2, 3, 4].
22 * However, splitting into [1, 0], [2], [3], [4] is the highest number of chunks possible.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	n == arr.length
28 * 	1 <= n <= 10
29 * 	0 <= arr[i] < n
30 * 	All the elements of arr are unique.
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/max-chunks-to-make-sorted/
36// discuss: https://leetcode.com/problems/max-chunks-to-make-sorted/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn max_chunks_to_sorted(arr: Vec<i32>) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_769() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.