-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC769.java
More file actions
43 lines (34 loc) · 957 Bytes
/
LC769.java
File metadata and controls
43 lines (34 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* LC769
*/
import java.util.*;
public class LC769 {
public static int maxChunksToSorted(int[] arr) {
int max = Integer.MIN_VALUE;
int n = arr.length;
int count = 0;
for (int i = 0; i < n; i++) {
max = Math.max(max, arr[i]);
if (max < i + 1) {
count++;
}
}
return count;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter The Array Size : ");
int n = sc.nextInt();
System.out.println();
int[] arr = new int[n];
System.out.println("Enter The Array Elements : ");
for (int i = 0; i < arr.length; i++) {
System.out.printf("[%d] : ", i);
arr[i] = sc.nextInt();
}
System.out.println();
int ans = maxChunksToSorted(arr);
System.out.println(ans);
sc.close();
}
}