@@ -0,0 +1,968 @@
+// My solution, runs in O(n%5E2) time and O(n) space (actually k chunks, but there can be at most n%0A// chunks). Not particularly efficient solution, takes 4ms to run all test cases.%0Aclass Solution %7B%0A  public int maxChunksToSorted(int%5B%5D arr) %7B%0A    int chunks = 0, end = arr.length - 1;%0A    while (end %3E= 0) %7B%0A      end = locateChunk(arr, end) - 1;%0A      chunks++;%0A    %7D%0A    return chunks;%0A  %7D%0A%0A  private int locateChunk(int%5B%5D arr, int end) %7B%0A    int min = end;%0A    while (end %3E= 0 && arr%5Bend%5D != min) %7B%0A      int j = arr%5Bend%5D;%0A      while (arr%5Bj%5D != j) %7B%0A        int t = arr%5Bj%5D;%0A        arr%5Bj%5D = j;%0A        j = t;%0A        min = Math.min(min, j);%0A      %7D%0A      end--;%0A    %7D%0A    return min;%0A  %7D%0A%7D%0A%0A// Official solution runs in O(n) time and O(1) space.%0Aclass Solution %7B%0A  public int maxChunksToSorted(int%5B%5D arr) %7B%0A    int ans = 0, max = 0;%0A    for (int i = 0; i %3C arr.length; ++i) %7B%0A      max = Math.max(max, arr%5Bi%5D);%0A      if (max == i) ans++;%0A    %7D%0A    return ans;%0A  %7D%0A%7D%0A

add solution