java.lang.Object
g0701_0800.s0769_max_chunks_to_make_sorted.Solution

public class Solution extends Object
769 - Max Chunks To Make Sorted.<p>Medium</p> <p>You are given an integer array <code>arr</code> of length <code>n</code> that represents a permutation of the integers in the range <code>[0, n - 1]</code>.</p> <p>We split <code>arr</code> into some number of <strong>chunks</strong> (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.</p> <p>Return <em>the largest number of chunks we can make to sort the array</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> arr = [4,3,2,1,0]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong></p> <pre><code> Splitting into two or more chunks will not return the required result. For example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted. </code></pre> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> arr = [1,0,2,3,4]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong></p> <pre><code> We can split into two chunks, such as [1, 0], [2, 3, 4]. However, splitting into [1, 0], [2], [3], [4] is the highest number of chunks possible. </code></pre> <p><strong>Constraints:</strong></p> <ul> <li><code>n == arr.length</code></li> <li><code>1 <= n <= 10</code></li> <li><code>0 <= arr[i] < n</code></li> <li>All the elements of <code>arr</code> are <strong>unique</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxChunksToSorted

      public int maxChunksToSorted(int[] arr)