Skip to content

Commit ac24bd1

Browse files
authored
Create Array-Beautiful Distribution
1 parent abd0780 commit ac24bd1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Array-Beautiful Distribution

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Problem statement
3+
4+
https://www.codingninjas.com/codestudio/contests/codestudio-weekend-contest-53/7079253/problems/22878
5+
6+
important
7+
8+
9+
public class Solution {
10+
static int maxGroups(int []a) {
11+
int sufixmin [] = new int[a.length];
12+
int min = Integer.MAX_VALUE;
13+
for(int i = a.length -1 ; i >=0 ;i--){
14+
if(min >= a[i]){
15+
min = a[i];
16+
sufixmin[i] = min;
17+
}else{
18+
sufixmin[i] = sufixmin[i+1];
19+
}
20+
}
21+
int count = 1;
22+
int currmax = a[0];
23+
for(int i =0 ;i<a.length -1 ;i++){
24+
currmax = Math.max(currmax , a[i]);
25+
if(sufixmin[i+1] >= currmax){
26+
count++;
27+
}
28+
}
29+
30+
return count;
31+
}
32+
}
33+
34+
35+
36+

0 commit comments

Comments
 (0)