MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / maxChunksToSorted

Method maxChunksToSorted

MaxChunksToMakeSortedII.java:3–20  ·  view source on GitHub ↗
(int[] arr)

Source from the content-addressed store, hash-verified

1class Solution
2{
3 public int maxChunksToSorted(int[] arr)
4 {
5 int[]right = new int[arr.length + 1];
6 right[arr.length] = Integer.MAX_VALUE;
7 for(int i = arr.length -1 ;i>=0 ;i--){
8 right[i] = Math.min(right[i+1] , arr[i]);
9 }
10 int count =0 ;
11 int min = Integer.MIN_VALUE;
12 for(int i =0 ; i < arr.length ;i++){
13 min = Math.max(min , arr[i]);
14
15 if(min <= right[i+1]){
16 count++;
17 }
18 }
19 return count;
20 }
21}
22
23

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected