We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent abd0780 commit ac24bd1Copy full SHA for ac24bd1
Array-Beautiful Distribution
@@ -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